Neither the onSelect()
nor onClick()
events are supported by the <option>
tag.(<option>
标记不支持onSelect()
和onClick()
事件。)
The former refers to selecting text (ie by clicking + dragging across a text field) so can only be used with the <text>
and <textarea>
tags.(前者是指选择文本(即通过单击+在文本字段上拖动),因此只能与<text>
和<textarea>
标记一起使用。) The onClick()
event can be used with <select>
tags - however, you probably are looking for functionality where it would be best to use the onChange()
event, not onClick()
.(onClick()
事件可以与<select>
标记一起使用-但是,您可能正在寻找最好使用onChange()
事件而不是onClick()
。)
Furthermore, by the look of your <c:...>
tags, you are also trying to use JSP syntax in a plain HTML document.(此外,通过<c:...>
标记的外观,您还试图在纯HTML文档中使用JSP语法。)
That's just... incorrect.(那只是...不对。)
In response to your comment to this answer - I can barely understand it.(回应您对这个答案的评论-我几乎无法理解。)
However, it sounds like what you want to do is get the value of the <option>
tag that the user has just selected whenever they select one.(但是,听起来您想做的就是获取用户选择时刚刚选择的<option>
标记的值。) In that case, you want to have something like:(在这种情况下,您希望拥有以下内容:)
<html>
<head>
<script type="text/javascript">
function changeFunc() {
var selectBox = document.getElementById("selectBox");
var selectedValue = selectBox.options[selectBox.selectedIndex].value;
alert(selectedValue);
}
</script>
</head>
<body>
<select id="selectBox" onchange="changeFunc();">
<option value="1">Option #1</option>
<option value="2">Option #2</option>
</select>
</body>
</html>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…