简体   繁体   English

如何在javascript中触发更改事件?

[英]how to trigger change event in javascript?

i am trying to make my 4th checkbox enabled as soon as there is a new value in my textbox (myinput). 我试图在我的文本框(myinput)中有新值时立即启用第4个复选框。 If it is empty than disable this. 如果为空,则禁用此功能。 At the moment you have to tab out before the changing event is triggered? 目前,您必须先退出,然后再触发更改事件? Also:how can I check for an empty textbox? 另外:如何检查文本框是否为空?

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="myinput" type="text" onchange="Changing();" />
        <asp:CheckBoxList runat="server" TextAlign="Right">
            <asp:ListItem Text="een">

            </asp:ListItem>
            <asp:ListItem Text="twee">

            </asp:ListItem>
            <asp:ListItem Text="drie">

            </asp:ListItem>
            <asp:ListItem Text="vier">

            </asp:ListItem>
        </asp:CheckBoxList>
    </div>
    </form>
</body>
</html>
<script language="javascript">

    function Changing() {
        //alert('changing', document.getElementById('myinput').value);
        if (document.getElementById('myinput').value == '') {
            document.getElementById('ctl02_3').disabled = true;
        }
        else {
            document.getElementById('ctl02_3').disabled = false;
        }
    }

</script>

You can use the onkeyup event which will fire as the textbox value changes. 您可以使用onkeyup事件,该事件将在文本框值更改时触发。

See here: http://www.w3schools.com/jsref/event_onkeyup.asp 看到这里: http : //www.w3schools.com/jsref/event_onkeyup.asp

Also the onkeydown and onkeypress events will yield similar results 同样, onkeydownonkeypress事件将产生相似的结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM