首页
学习
活动
专区
工具
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中如何判断数组中包含某个特定_js数组是否包含某个

array.indexOf 判断数组中是否存在某个,如果存在返回数组元素下标,否则返回-1 let arr = ['something', 'anything', 'nothing',...anything']; let index = arr.indexOf('nothing'); # 结果:2 array.includes(searchElement[, fromIndex]) 判断一个数组是否包含一个指定...参数:searchElement 需要查找元素。 参数:thisArg(可选) 从该索引处开始查找 searchElement。...); # 结果: true result = numbers.includes(118); # 结果: false array.find(callback[, thisArg]) 返回数组中满足条件第一个元素...方法,该方法返回元素在数组中下标,如果不存在与数组中,那么返回-1; 参数:searchElement 需要查找元素

18.3K40
领券