jQuery serialize()
从表单中抛出空字符串,这是表单的源
<form accept-charset="UTF-8" action="/asdf" id="form_for_asdf_1_option_1" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="asdfaaqwefasdfwefefsefefwew=" /></div>
<input name="checkbox_update_vote[asdf_id]" type="hidden" value="0" /><input id="dbr_1_of_asdf_1" name="checkbox_update_vote[asdf_id]" type="checkbox" value="1" />
<input id="option_1_of_asdf_1" name="checkbox_update_vote[option_id]" type="hidden" value="1" />
<input id="del_1_of_asdf_1" name="checkbox_update_vote[del]" type="hidden" value="false" />
<br />
</form>
以及用于显示序列化输出的 JavaScript。
$(document).ready(function() {
$('input[type="checkbox"]').change(function() {
alert($($(this).parents("form")[0].id).serialize());
});
});
有人可以指出我哪里做错了吗?
最佳答案
添加“#”:
$("#" + $(this).parents("form")[0].id)
或删除.id
:
$($(this).parents("form")[0])
关于jQuery serialize() 在 Rails 中抛出空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10053079/