js 触发事件(input onchange )


<input name="txt" type="text" id="txt" onchange="txtChange()"/>
< input type="submit" name="Submit" value="点击我,让文本框获取焦点,同时触发onchange事件" onclick="clickMe()"/>
< script>
function clickMe()
{
        var o=document.getElementById("txt");
        o.focus();
        o.value="hello world!";//自动赋值以后文本框已经change,理论上要发生onchange事件
        //但是如果不加以下这句是不会触发onchange事件的
        o.fireEvent("onchange");
}
function txtChange()
{
        alert("同时触发了onchange事件");
}
< /script>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM