如何用javascript取得<html:select>中<html:option>的值?

如何用javascript取得<html:select>中<html:option>的值?,第1张

每一个选择框select都有一个options的列表对象。

<select id="subject" name="subject">

<option value="one">文本值1</option>

<option value="two">文本值2</option>

<option value="three">文本值3</option>

</select>

使用:options[2].value,这样可以得到值“three”;使用options[2].text,得到“文本值3”

为<html:select>定义id属性,然后在JS中使用document.getElementById("")就可以对他进行 *** 作了~

比如你要做赋值,可以这么写~

<html:select id="test"></html:select>

<script>

document.getElementById("test").value="1"

</script>


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

原文地址: https://outofmemory.cn/zaji/6159117.html

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

发表评论

登录后才能评论

评论列表(0条)

保存