1

如果我的问题重复,我深表歉意。我研究了所有相同的问题并做了以下事情:1.删除所有禁用的输入字段。2.检查是否有重复的id。没有 id 重复。3. 每个表单域都有一个名称。但以下代码返回空字符串:

$('#answer_sheet_btn').click(function(e){
        e.preventDefault();
        console.log( $( this ).serializeArray() );

  });

这是我的表格:

<form method="post" action="/wordpress/wp-admin/admin.php?page=active-exam&amp;exam_id=1" id="question_paper">
        <p></p><table class="bix-tbl-container" style="height: 40px" border="0" width="533" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="bix-td-qtxt" valign="top">If 60 J of energy are available for every 15 C of charge, what is the voltage?</td>
</tr>
</tbody>
</table><p></p>
    <input name="opt1[]" type="checkbox" value="1">60 V <input name="opt1[]" type="checkbox" value="2">4 V  <input name="opt1[]" type="checkbox" value="3">15 V <input name="opt1[]" type="checkbox" value="4">.25 V    <hr>

    <p>Which resistive component is designed to be temperature sensitive?</p>
    <input name="opt2[]" type="checkbox" value="1">Rheostat <input name="opt2[]" type="checkbox" value="2">Thermistor   <input name="opt2[]" type="checkbox" value="3">Potentiometer    <input name="opt2[]" type="checkbox" value="4">Photoconductive cell <hr>

<input type="hidden" name="q_ids" value="1,2">
<p class="submit">
    <input type="submit" name="answer_sheet" id="answer_sheet_btn" class="button-primary" value="submit">
</p>

</form>

这杀死了我的一天。我想我在做一些愚蠢的类型错误。请指出。

注意:我尝试删除隐藏字段

<input type="hidden" name="q_ids" value="1,2">
4

1 回答 1

1

根据.serializeArray()

.serializeArray() 方法创建一个 JavaScript 对象数组,准备好编码为 JSON 字符串。它在表单和/或表单控件的 jQuery 集合上运行。

您应该处理表单提交操作,然后序列化表单:

$('#question_paper').submit(function(e){
    e.preventDefault();
    console.log( $(this).serializeArray() );
});

$('#question_paper').submit(function(e){
    e.preventDefault();
    console.log( $(this).serializeArray() );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" action="/wordpress/wp-admin/admin.php?page=active-exam&amp;exam_id=1" id="question_paper">
  <p></p>
  <table class="bix-tbl-container" style="height: 40px" border="0" width="533" cellspacing="0" cellpadding="0">
<tbody>
  <tr>
    <td class="bix-td-qtxt" valign="top">If 60 J of energy are available for every 15 C of charge, what is the voltage?</td>
  </tr>
</tbody>
  </table>
  <p></p>
  <input name="opt1[]" type="checkbox" value="1">60 V
  <input name="opt1[]" type="checkbox" value="2">4 V
  <input name="opt1[]" type="checkbox" value="3">15 V
  <input name="opt1[]" type="checkbox" value="4">.25 V
  <hr>

  <p>Which resistive component is designed to be temperature sensitive?</p>
  <input name="opt2[]" type="checkbox" value="1">Rheostat
  <input name="opt2[]" type="checkbox" value="2">Thermistor
  <input name="opt2[]" type="checkbox" value="3">Potentiometer
  <input name="opt2[]" type="checkbox" value="4">Photoconductive cell
  <hr>

  <input type="hidden" name="q_ids" value="1,2">
  <p class="submit">
<input type="submit" name="answer_sheet" id="answer_sheet_btn" class="button-primary" value="submit">
  </p>

</form>

于 2017-12-26T16:46:55.970 回答