Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从JQUERY中的表单元素获取值?_Jquery - Fatal编程技术网

从JQUERY中的表单元素获取值?

从JQUERY中的表单元素获取值?,jquery,Jquery,My form.html <form id="search-form" method="post" action="." name="f"> <p><label for="id_customer_type">Customer type</label> <select name="customer_type" id="id_customer_type"> <option value="">All</option>

My form.html

<form id="search-form" method="post" action="." name="f">
<p><label for="id_customer_type">Customer type</label> <select name="customer_type" id="id_customer_type">
<option value="">All</option>
<option value="TDO" selected="selected">TDO</option>
</select></p>
<p><label for="id_tag">Tag</label> </p><dl>
<dt><strong>School</strong></dt>
<dd><label for="id_tag_1"><input checked="checked" name="tag" value="2" id="id_tag_1" type="checkbox"> Private</label></dd>

<dd><label for="id_tag_2"><input checked="checked" name="tag" value="3" id="id_tag_2" type="checkbox"> Public</label></dd>
</dl> 
<input id="filter" value="Filter" type="submit"> 
</form>
谢谢!:)

val()
是正确的方法,但未考虑选中的
复选框的范围

您必须在匿名函数之外声明变量:

$(document).ready(function(){

    var checkboxs_ischecked; // ADD THIS LINE

    $("input[type='checkbox']:checked").each(function(){
        checkboxs_ischecked = $("input[type='checkbox']").val();
    });

...

你们是想随便做一个单选按钮吗?这不应该起作用,因为他正在document.ready上检查它。用户可能在提交之前修改了信息,这段代码应该在$(“#filter”).click()函数中。
$(document).ready(function(){

    var checkboxs_ischecked; // ADD THIS LINE

    $("input[type='checkbox']:checked").each(function(){
        checkboxs_ischecked = $("input[type='checkbox']").val();
    });

...