在此的jsfiddle这个JavaScript为什么会失败?
有我的条纹下来的问题。
尝试点击“保存”,你会看到你得到一个提醒。
现在点击“签名”或“A”。这些行现在使用TableSorter排序。
现在点击“保存”,然后什么也没有发生,我预计会再次看到警告框。
问题
有人能想出解决的JavaScript,因此该行已被排序即使在保存按钮的工作原理?
HTML
<div class="page-body">
<table class="alerts tablesorter" id="accTable" cellspacing="0">
<thead>
<tr class="header">
<th class="activity-header"> A </th>
<th class="activity-header"> Signed </th>
<th class="activity-header"> </th>
</tr>
</thead>
<tbody>
<form action="" method="post">
<input name="anchor" value="7249" type="hidden">
<tr class="row" id="7249">
<td class="activity-data">7249</td>
<!-- tablesorter can't sort a column with check boxes out-of-the-box, so it needs something to sort on. That is why the span tag is here -->
<!-- a jquery script is watching the state of the checkbox, so when clicked the value in the span is updated -->
<td class="checkbox"> <span style="display:none;">0</span> <input name="signed" type="checkbox" > </td>
<td class="edit-column"> <input value="Save" type="submit"></td>
</tr>
</form>
<form action="" method="post">
<input name="anchor" value="61484" type="hidden">
<tr class="row" id="61484">
<td class="activity-data">61484</td>
<td class="checkbox"> <span style="display:none;">1</span> <input name="signed" type="checkbox" checked > </td>
<td class="edit-column"> <input value="Save" type="submit"></td>
</tr>
</form>
</tbody>
</table>
</div>
的JavaScript
$(document).ready(function() {
$("#accTable").tablesorter();
// :checkbox stops from executing the event on the save button. Same as input[type=checkbox]
$('#accTable input:checkbox').click(function() {
// insert 1 or 0 depending of checkbox state in the tag before the input tag. In this case <span> is before <input>
// this is done so tablesorter have something to sort on, as it doesn't support checkbox sort out of the box.
var order = this.checked ? '1' : '0';
$(this).prev().html(order);
$(this).parents("table").trigger("update");
});
});
// sends the form content to server side, and stay on page
$('form').live('submit', function() {
alert('test');
// don't redirect
return false;
});
正如答案所说,你不能在'tbody'里面有'form'。 Firefox甚至可以从一开始就纠正错误,因此在Firefox中,单击按钮将重新加载页面并且不显示警报。 –