为什么onchange不起作用? [英] Why onchange doesn't work?

查看:135
本文介绍了为什么onchange不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在网上寻找答案,但尚未找到任何答案.我正在使用Google的api翻译,而JS则有问题.实际上,我的代码只执行一次操作就可以100%正常.

I'm just looking for an answer on the net but I haven't reached any one. I'm playing with google's api translation and I have a problem with JS. In fact my code is 100% ok except one operation.

我的问题是当时没有给出翻译.在js将信息发送给google之后,它不会等到给出翻译后再进行操作.取而代之的是,它继续读取我的代码,因此不会停止获取答案.它会处理要翻译的信息,然后会在一段时间后得到答案.因此,因为我想进行翻译,所以我做了一个甜蜜的循环.因为我不知道如何停止js,所以我用不同的输入文本框完成了一个页面,并且在循环中,当接收到数据时,它将发送到文本框的值,这就是问题所在.当文本更改时,我想再次输入我的js函数,因此如果js更改了值,则在获得翻译后它将返回我的循环.简单有效,但是如果我在输入框中输入:

My problem is that the translation is not given at the time. After js sends the information to google it doesn't wait until the translation is given. Instead of this it continues reading my code so it doesn't stop for get an answer. It proceess the information to be translated and then the answer will be get some time after. So because I want to do translations of translations I have done a sweet loop. Because I don't know how to stop js, I have done a page with diferent inputs text box and in my loop when the data is received it's send to the value of the text box and here is where it becomes the problem. I want to enter to my js function again when the text is changed so If js changes the value it will return to my loop when I get the translation. Simply and effective but if I put in the input box:

onchange="myfunction()"

循环无效.但是最奇怪的是,如果我手动更改文本,则该函数起作用,因此好像onchange仅在人类更改文本时起作用,而在js更改文本时不起作用.有什么解决办法吗?可能是一些动态听众或诸如此类的东西?

the loop doesn't work. But the strangest is that if I manually change the text then the function works so it's as if onchange only works when a human change the text but not if js change the text. Is there any solution? May be some dinamic listener or something like that?

推荐答案

仅当用户更改输入值时才会触发onchange事件.如果以编程方式更改输入,则不应触发.

The onchange event only fires if the user changes the value of the input. It isn't supposed to fire if the input is changed programmaticly.

从任何设置该值的函数中调用该函数.

Call the function from whatever function sets the value instead.

这篇关于为什么onchange不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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