以编程方式更新时,不会调用HTML JavaScript onChange Handler [英] HTML JavaScript onChange Handler is not called when updated programatically

查看:75
本文介绍了以编程方式更新时,不会调用HTML JavaScript onChange Handler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现HTML文本框和JavaScript出现了奇怪的异常,我将其缩小为html/javascript的特殊性,我希望有人可以对此进行教育.

I have found an odd anomaly with HTML text boxes and JavaScript that I have narrowed down to being a html/javascript peculiarity and I'm hoping someone can educate me on.

我已经下载并实现了日历插件,该插件可创建带有日历的简单图层,并在选择时将所选日期传递回文本框.

I have downloaded and implemented a calendar plug-in that creates a simple layer with a calendar and on selection, passes the selected date back to the text box.

我想做的是在文本框更改时捕获(使用onchange),然后调用Ajax函数来更新数据库...

What I want to do is catch when the text box changes (using onchange) and then call an Ajax function to update the database...

问题是,永远不会调用onchange ...我已经可以通过下面的这个非常简单的代码来证明它...单击按钮时,它会更改值,然后触发onchange并显示一个警告框...

The problem is, onchange never gets called... I have been able to prove it with this very simple code below... When the button is clicked it changes the value which should then trigger the onchange and display an alert box...

<input type="button" name="setValue" id="setValue" value="setValue" onClick="document.getElementById('textinput').value='Updated'">&nbsp;
<input type="button" name="clearValue" id="clearValue" value="clearValue" onClick="document.getElementById('textinput').value=''"><br>
<input type="text" name="textinput" id="textinput" onChange="alert(this.name)">

这是标准吗?有解决方法吗?

Is this standard? Is there a workaround?

推荐答案

仅当元素失去焦点时,并且如果它的值现在不是焦点时的值,才触发文本框和textarea元素上的onchange事件.

The onchange event on textboxes and textarea elements only fires when the element loses focus, and if its value is now other than its value when it got focus.

这篇关于以编程方式更新时,不会调用HTML JavaScript onChange Handler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆