首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

js:如何获取select选中

我想获取select选中value,或者text,或者…… 比如这个: <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 版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人

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

js、jQuery 获取文档、窗口、元素各种

window.screen.width 屏幕可用工作区高度: window.screen.availHeight 屏幕可用工作区宽度: window.screen.availWidth jQuery: 文档:是包括滚动条所有的内容 获取浏览器显示区域...(可视区域)高度 : $(window).height(); 获取浏览器显示区域(可视区域)宽度 : $(window).width(); 获取页面的文档高度:$(document).height(...top; 某个元素左边界距文档最左边距离:obj.offset().left; 鼠标移动: screenY: 鼠标相对于显示器屏幕左上角偏移 pageY: 鼠标相对于页面左上角偏移...(其会受滚动条影响,相当于整个文档,整个页面的Y) IE9之下并不支持这个属性 clientY: 鼠标相对于浏览器窗口左上角偏移(其不会受滚动条影响,相对于滚动条当前位置浏览窗口...2.在元素具有上边框border-top情况下, layerY比offsetY多一个border-top宽度

14K32

JS操作表单select详解-选取当前、重置option等

JS操作表单select详解-选取当前、重置option等 对于表单(form)中常用select选项,经常牵涉到选取optionindex、value及文本中,本文结合着实例对其进行讲解。...一个select如下 pre option1 option2 option3 option4 option5 next 代码效果图 select中常用操作如下: 1.获取select对象; var...sel=document.querySelector(“#choose”); 2.获取select选中optionindex; var index=sel.selectedIndex; 3.获取select...选中option value; var val=sel.options[index].value; 4.获取select选中optiontext; var text=sel.options[index...= selarr.length;//select 长度; function getOptionName(){ let first = sel.selectedIndex; //获取改变后

25910
领券