![](/img/trans.png)
[英]how to replace the forward slash to backslash and forward slash using javascript
[英]How to get the value of an option element with a forward slash using javascript?
我有一个带有多个选项的select
元素,例如:
<option value="test/foobar">test/foobar</option>
当我尝试通过获取此值
var selectedValue = select.options[select.selectedIndex].value;
只要该值不包含/
所有方法都可以正常工作,如果该值中包含一个值,则selectedValue
的内容仅是test
而不是test/foobar
就像我期望的那样。
我怎样才能获得与完整的价值/
无jQuery的?
这个解决方案对我有用。
select
输入看起来像这样。
<select id="selector">
<option value="test/foobar1">test/foobar1</option>
<option value="test/foobar2">test/foobar2</option>
</select>
js看起来像这样。
var e = document.getElementById("selector");
var selectedVal = e.options[e.selectedIndex].value;
console.log(selectedVal);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.