onChange&需要onClick帮助 [英] onChange & onClick help needed
问题描述
我有一个下拉菜单,我想为每个选定的项目执行onClick onclick操作.
似乎这是不可能的,我发现代码使用onChange,因此我将操作添加到了它.
_doBanMe(''<%=strName%>'', <%=strUid%>,''xxxxxxxxxxxx'');
但是现在我要做的是代替xxxxxxxxxxxx,我想将选定的项目值发送到_doBanM
函数
我的代码
I have a drop-down menu and I wanted to do onClick onclick action for every selected item.
It seems this is not possible and I found that the code use onChange so I add my action to it.
_doBanMe(''<%=strName%>'', <%=strUid%>,''xxxxxxxxxxxx'');
but now what I want to do is instead of xxxxxxxxxxxx I want to send the selected item value to _doBanM
function
My Code
<td align="center">
<select style="font-size:9pt" önChange="JavaScript:CtrlPan(this.options[this.selectedIndex].value);this.selectedIndex=0;_doBanMe(''<%=strName%>'', <%=strUid%>,''xxxxxxxxxxxx'');">
<option value=0>test</option>
<option value=1>test1</option>
<option value=3>test2</option>
<option value=4>test3</option>
</select></td>
推荐答案
让我给您简单的代码:您只需要select
元素的value
,您可以自行决定其他所有内容,使用这个主意:
Let me give you simplified code: you just need thevalue
of theselect
element, everything else you can decide on your own, using the idea:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript"><!--
function eventHandler(event) {
alert(event.type);
alert(event.value);
}
--></script>
</head>
<body>
<select style="font-size:12pt" onChange="event.value = value; eventHandler(event)">
<option value="0">test 0</option>
<option value="1">test 1</option>
<option value="2">test 2</option>
<option value="3">test 3</option>
</select>
</body>
</html>
当然,您可以使用多个参数.而且您不必使用event
对象(这是一个加成:-)).
与事件onКeyPress
相同的故事.事件对象在这里更有用:您可以使用event.keyCode
和event.which
.如果从onКeyPress
事件处理程序返回false
,则将抑制按键,这对于过滤(忽略)不需要的按键非常有用.
回答后续问题:
这是基于您在代码中尝试执行的操作的简化变体.不要说我不知道如何使用";这与您尝试编写的内容相同,只是简单而正确.您需要做的只是用所需的代码替换alert
.您想要一个选定的值,仅此而已.参数将从选定的value
中获取,即0、1,依此类推.
You can use several parameters, of course; and you do not have to use event
object (that is a bonus :-)).
Same story with the event onКeyPress
. The event object is more useful here: you can use event.keyCode
and event.which
. If you return false
from onКeyPress
event handler, a key press will be suppressed, which is very useful to filter out (ignore) the unwanted key presses.
Answering follow-up question:
This is the simplified variant based on what you tried to do in your code. Don''t say "I don''t know how to use it"; this is the same as you tried to write, only simple and correct. All you need to do is replacing alert
with the code you wanted. You wanted to get a selected value, that''s it. A parameter will be taken from selected value
, that is, 0, 1, and so on.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript"><!--
function eventHandler(value) {
alert(value);
}
--></script>
</head>
<body>
<select style="font-size:12pt" onChange="eventHandler(value)">
<option value="0">test 0</option>
<option value="1">test 1</option>
<option value="2">test 2</option>
<option value="3">test 3</option>
</select>
</body>
</html>
这篇关于onChange&需要onClick帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!