首页
学习
活动
专区
圈层
工具
发布

js:如何获取select选中的值

我想获取select选中的value,或者text,或者…… 比如这个: select id=”select”> <option value=”A” url=”http://www.baidu.com...JavaScript原生的方法 1:拿到select对象: `var myselect=document.getElementById(“select”); 2:拿到选中项的索引:var index=myselect.selectedIndex...的text: myselect.options[index].text; 5:拿到选中项的其他值,比如这里的url: myselect.options[index].getAttribute(‘url’...); 二:jQuery方法 1:var options=$(“#select option:selected”); //获取选中的项 2:alert(options.val()); //拿到选中项的值...3:alert(options.text()); //拿到选中项的文本 4:alert(options.attr(‘url’)); //拿到选中项的url值 版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人

32.9K30
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    checkbox选中和不选中的值_设置checkbox选中状态

    1.设置选中:$(“#hasApply”).prop(“checked”,true); 设置不选中:$(“#hasApply”).prop(“checked”,false); 或如下方法: // $(...“#ck”).attr(“checked”,true)//选中 // $(“#ck”).attr(“checked”,false)//未选中 2.获取选中的状态:var status = $(“#hasApply...”).prop(“checked”); 3.判断checkbox是否选中的3种方法 方法一: if ((“#checkbox-id”).get(0).checked) { // do something...((‘#checkbox-id’).attr(‘checked’)) { // do something } 注意:在jQuery1.6版本之后,这个方法返回的是undefined;取复选框有没有被选中...,要用prop,返回true/false if((‘#checkbox-id’).prop(‘checked’)) {   //do something } 获取选择 radio 的值 发布者:全栈程序员栈长

    9.7K20
    领券