Metasearch - 按下复选框时帮助处理 Jquery ajax 请求
我想在按下 true 或 false 复选框时发出 Jquery ajax 请求。
我的表格:
<form method="get" action="/" accept-charset="UTF-8"><div style="margin: 0pt; padding: 0pt; display: inline;"><input name="utf8" value="✓" type="hidden"></div>
<div class="menuitem">
<label for="search_company1">company1</label>
<input name="search[company1_is_true]" value="0" type="hidden"><input id="search_company1_is_true" name="search[company1_is_true]" value="1" type="checkbox">
</div>
<div class="menuitem">
<label for="search_company2">company2</label>
<input name="search[company2_is_true]" value="0" type="hidden"><input id="search_company2_is_true" name="search[company2_is_true]" value="1" type="checkbox">
</div>
<div class="menuitem">
<label for="search_company3">company3</label>
<input name="search[company3_is_true]" value="0" type="hidden"><input id="search_company3_is_true" name="search[company3_is_true]" value="1" type="checkbox">
</div>
<input id="search_submit" name="commit" value="Create Search" type="submit">
</form>
I want to make a Jquery ajax request when a checkbox pressed either true or false.
My form:
<form method="get" action="/" accept-charset="UTF-8"><div style="margin: 0pt; padding: 0pt; display: inline;"><input name="utf8" value="✓" type="hidden"></div>
<div class="menuitem">
<label for="search_company1">company1</label>
<input name="search[company1_is_true]" value="0" type="hidden"><input id="search_company1_is_true" name="search[company1_is_true]" value="1" type="checkbox">
</div>
<div class="menuitem">
<label for="search_company2">company2</label>
<input name="search[company2_is_true]" value="0" type="hidden"><input id="search_company2_is_true" name="search[company2_is_true]" value="1" type="checkbox">
</div>
<div class="menuitem">
<label for="search_company3">company3</label>
<input name="search[company3_is_true]" value="0" type="hidden"><input id="search_company3_is_true" name="search[company3_is_true]" value="1" type="checkbox">
</div>
<input id="search_submit" name="commit" value="Create Search" type="submit">
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 menuitem 类中的任何复选框更改为 true 或 false 后,这将启动自定义 doAjaxRequest 函数。
回答第一条评论问题:
虽然您可能想为表单定义一些 id 并使用它而不仅仅是表单选择器: $('#formId')
EDIT
我刚刚对您有问题的代码和我的第二个答案做了 jsfiddle,它似乎有效:
http://jsfiddle.net/dUPmg/
This launches custom doAjaxRequest function after any of the checkboxes in menuitem class are changed to either true or false.
Answer to first comment question:
Though you probably want to define some id to your form and use it instead of just form selector: $('#formId')
EDIT
I just made jsfiddle of your code in question and my second answer and it seems to work:
http://jsfiddle.net/dUPmg/
应该是一个相当简单的任务:
这会将更改事件处理程序绑定到每个复选框元素。当这些元素的数量增加时,您应该转而使用委托的更改事件。
Should be a fairly trivial task:
That would bind a change-eventhandler to each checkbox element. When the number of those elements increases, you should go for a delegated change-event instead.