关于js中获取到combobox选中值的问题!!

关于js中获取到combobox选中值的问题!!,第1张

Html代码  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 401 Transitional//EN" ">

<input type="checkbox" name="student" value="1" data-age="18" />

<input type="checkbox" name="student" value="2" data-age="19" />

<input type="checkbox" name="student" value="3" data-age="20" />

var student = $("input[name='student']:checked")serialize();

$ajax({

url: "your-url",

type: "post",

data: student,

success: function (result) {

//handle

}

});

如果3个都是选中的状态的话,后台接收的数据为1,2,3

扩展资料:

关于jQuery对checkbox的其他 *** 作

1、根据id获取checkbox

$("#cbCheckbox1");

2、获取所有的checkbox

$("input[type='checkbox']");//or

$("input[name='cb']");

3、获取所有选中的checkbox

$("input:checkbox:checked");//or

$("input:[type='checkbox']:checked");//or

$("input[type='checkbox']:checked");//or

$("input:[name='ck']:checked");

4、获取checkbox值

//用val()即可,比如:

$("#cbCheckbox1")val();

5、获取多个选中的checkbox值

var vals = [];

$('input:checkbox:checked')each(function (index, item) {

valspush($(this)val());

});

6、判断checkbox是否选中(jquery 16以前版本 用  $(this)attr("checked"))

$("#cbCheckbox1")click(function () {

if ($(this)prop("checked")) {

alert("选中");

} else {

alert("没有选中");

}

});

7、设置checkbox为选中状态

$('input:checkbox')attr("checked", 'checked');//or

$('input:checkbox')attr("checked", true);

8、设置checkbox为不选中状态

$('input:checkbox')attr("checked", '');//or

$('input:checkbox')attr("checked", false);

9、设置checkbox为禁用状态(jquery<16用attr,jquery>=16建议用prop)

$("input[type='checkbox']")attr("disabled", "disabled");//or

$("input[type='checkbox']")attr("disabled", true);//or

$("input[type='checkbox']")prop("disabled", true);//or

$("input[type='checkbox']")prop("disabled", "disabled");

10、设置checkbox为启用状态(jquery<16用attr,jquery>=16建议用prop)

$("input[type='checkbox']")removeAttr("disabled");//or

$("input[type='checkbox']")attr("disabled", false);//or

$("input[type='checkbox']")prop("disabled", "");//or

$("input[type='checkbox']")prop("disabled", false);

//

您这问题比模糊确认一下需求吧,

复选框子元素输入框的内容是什么?

点击事件中取得复选框选中的单元格值

var products = [];

var ordernums = [];

var ordernums1 = [];

var $span = $('fr-checkbox-checkon'); //获取选中的复选框

var $tds = $("td")has($span); //定义选中复选框的单元格

var $trs = $("tr")has($tds);

for(var i=0; i<$trslength;i++){

var product = $("td:eq(2)",$($trs[i]))html(); //获取选中行第二个单元格的值

productspush(product); //将选中的值放到数组中

var ordernum = $("td:eq(3)",$($trs[i]))html(); //获取选中行的第3个单元格的值

ordernumspush(ordernum);

var ordernum1 = $("td:eq(6)",$($trs[i]))html(); //获取选中I行的第6个单元格的值

ordernums1push(ordernum1);

}

alert(products + ";" + ordernums + ";" + ordernums1);

————————————————

js:

//js获取复选框值

var obj = documentgetElementsByName("interest");//选择所有name="interest"的对象,返回数组

var s='';//如果这样定义var s;变量s中会默认被赋个null值

for(var i=0;i<objlength;i++){

if(obj[i]checked) //取到对象数组后,我们来循环检测它是不是被选中

s+=obj[i]value+','; //如果选中,将value添加到变量s中

}

jquery:

//jquery获取复选框值

var chk_value =[];//定义一个数组

$('input[name="interest"]:checked')each(function(){//遍历每一个名字为interest的复选框,其中选中的执行函数

chk_valuepush($(this)val());//将选中的值添加到数组chk_value中

});

本篇文章是关于jQuery对select的 *** 作进行了总结介绍 需要的朋友可以参考下  

//遍历option和添加 移除option function changeShipMethod(shipping){  var len = $("select[@name=ISHIPTYPE] option") length  if(shipping value != "CA"){   $("select[@name=ISHIPTYPE] option") each(function(){    if($(this) val() == ){     $(this) remove();    }   });  }else{   $("<option value= >UPS Ground</option>") appendTo($("select[@name=ISHIPTYPE]"));  } } //取得下拉选单的选取值 $( #testSelect option:selected ) text(); $("#testSelect") find( option:selected ) text(); $("#testSelect") val(); ////////////////////////////////////////////////////////////////// 记性不好的可以收藏下 下拉框: var cc    = $(" formc select[@name= country ] option[@selected]") text(); //得到下拉菜单的选中项的文本(注意中间有空格) var cc = $( formc select[@name="country"] ) val();   //得到下拉菜单的选中项的值 var cc = $( formc select[@name="country"] ) attr("id"); //得到下拉菜单的选中项的ID属性值 $("#select") empty();//清空下拉框//$("#select") ( ); $("<option value= > </option>") appendTo("#select")//添加下拉框的option

稍微解释一下: select[@name= country ] option[@selected] 表示具有name 属性 并且该属性值为 country 的select元素 里面的具有selected 属性的option 元素 可以看出有@开头的就表示后面跟的是属性

单选框: $("input[@type=radio][@checked]") val();   //得到单选框的选中项的值(注意中间没有空格) $("input[@type=radio][@value= ]") attr("checked" checked ); //设置单选框value= 的为选中状态 (注意中间没有空格)

复选框: $("input[@type=checkbox][@checked]") val(); //得到复选框的选中的第一项的值 $("input[@type=checkbox][@checked]") each(function(){ //由于复选框一般选中的是多个 所以可以循环输出    alert($(this) val());    });

$("#c ") attr("checked" );//不打勾 $("#c ") attr("checked" true);//打勾 if($("#c ") attr( checked )==undefined){} //判断是否已经打勾 当然jquery的选择器是强大的 还有很多方法 <script src=jquery js type=text/javascript></script> <script language="javascript" type=text/javascript> $(document) ready(function(){ $("#selectTest") change(function() {        //alert("Hello");        //alert($("#selectTest") attr("name"));        //$("a") attr("href" "xx ");        //window location href="xx ";        //alert($("#selectTest") val());        alert($("#selectTest option[@selected]") text());        $("#selectTest") attr("value" " ");

}); }); </script>

<a href="#">aaass</a> <! 下拉框 > <select id="selectTest" name=selectTest> <option value=" "> </option> <option value=" "> </option> <option value=" "> </option> <option value=" "> </option> <option value=" "> </option> <option value=" "> </option> </select> jquery radio取值 checkbox取值 select取值 radio选中 checkbox选中 select选中 及其相关获取一组radio被选中项的值 var item = $( input[@name=items][@checked] ) val(); 获取select被选中项的文本 var item = $("select[@name=items] option[@selected]") text(); select下拉框的第二个元素为当前选中值 $( #select_id )[ ] selectedIndex = ; radio单选组的第二个元素为当前选中值 $( input[@name=items] ) get( ) checked = true; 获取值 文本框 文本区域 $("#txt") attr("value") 多选框checkbox $("#checkbox_id") attr("value") 单选组radio $("input[@type=radio][@checked]") val(); 下拉框select $( #sel ) val(); 控制表单元素 文本框 文本区域 $("#txt") attr("value" );//清空内容                 $("#txt") attr("value" );//填充内容 多选框checkbox $("#c ") attr("checked" );//不打勾                 $("#c ") attr("checked" true);//打勾                 if($("#c ") attr( checked )==undefined) //判断是否已经打勾 单选组radio $("input[@type=radio]") attr("checked" );//设置value= 的项目为当前选中项 下拉框select $("#sel") attr("value" sel );//设置value= sel 的项目为当前选中项             $("<optionvalue= > </option><optionvalue= > </option>") appendTo("#sel")//添加下拉框的option             $("#sel") empty() //清空下拉框

lishixinzhi/Article/program/Java/JSP/201311/20142

1、获取复选框被选中值

<input type="button" id="btn5" value="获得选中的所有值">

<input type="text" name="dd" id="dd" size="50" />

$("#btn5")click(function(){

var str="";

$("[name='checkbox'][checked]")each(function(){

str+=$(this)val()+",";

})

$("#dd")val(str)

})

JQuery获取被选中复选框checkbox的个数

通过jQuery获取checkbox选中项的个数,需要用到jQuery的size()方法或length属性,下面的例子是通过length属性获得checkbox选中项的个数

<ul>

<li><input type="checkbox" name="test" />看电视</li>

<li><input type="checkbox" name="test" />看**</li>

<li><input type="checkbox" name="test" />上网</li>

<li><input type="checkbox" name="test" />爬山</li>

<li><input type="checkbox" name="test" />游乐场</li>

<li><input type="checkbox" name="test" />逛街</li>

<li><input type="checkbox" name="test" />聚会</li>

</ul>

<p>

<input type="button" id="count" value="有多少CheckBox被选中了?" />

<script type="text/javascript">

$(document)ready(function(){

$('input[type=checkbox]')click(function(){

$(this)attr('disabled','disabled');

if($("input[name='test']:checked")length >= 3)

{ $("input[name='test']")attr('disabled','disabled');}});

$("#count")click(function(){$('input')live('click',function(){    

alert($('input:checked')length);

});})})

</script>

效果如图:

扩展资料:

JS日常用途

嵌入动态文本于HTML页面。

对浏览器事件做出响应。

读写HTML元素。

在数据被提交到服务器之前验证数据。

检测访客的浏览器信息。

控制cookies,包括创建和修改等。

基于Nodejs技术进行服务器端编程。

以上就是关于关于js中获取到combobox选中值的问题!!全部的内容,包括:关于js中获取到combobox选中值的问题!!、在jsp中获取已选中checkbox其他列的值、jquery,ajax 如何提交多个checkbox的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9811506.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存