Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果我的输入值被Java方法更改,如何使用onchange事件调用JavaScript函数_Javascript_Html_Eclipse Jee - Fatal编程技术网

如果我的输入值被Java方法更改,如何使用onchange事件调用JavaScript函数

如果我的输入值被Java方法更改,如何使用onchange事件调用JavaScript函数,javascript,html,eclipse-jee,Javascript,Html,Eclipse Jee,我通过以下方式获得输入值: <input style="width:200px; display:none;" readonly="" type="text" id="abc" placeholder="30.30" value="#{position.layers}"></input> 如果我自己键入值,则会调用该方法,但如果值被“#{position.layers}”更改,则不会调用该函数 <input style="width:200px; display

我通过以下方式获得输入值:

<input style="width:200px; display:none;" readonly="" type="text" id="abc" placeholder="30.30" value="#{position.layers}"></input>
如果我自己键入值,则会调用该方法,但如果值被“#{position.layers}”更改,则不会调用该函数

 <input style="width:200px; display:none;" readonly="" type="text" id="abc" placeholder="30.30" value="#{position.layers}" onchange="callme()"></input>

最简单的方法是检查位置层的值,当它等于您要查找的值时,调用您的函数。比如说:

 function callme(){
    alert("ok");
   }

 function doNotCall(){
    alert("No Way");
    }

 if(position.layers == someValue){
      callme();
  }else{
      doNotCall();
  }

若使用其他平均值传递值,则不能直接触发更改事件

 var element = document.getElementById('abc');
 var event = new Event('change');
 element.dispatchEvent(event);
相反,您必须创建一个更改事件并尝试调用您的更改事件,
在您更改输入类型的值后添加上述代码。您的代码的其余部分可以不做任何更改。

为什么java标记?onchange事件只会在用户输入时触发。使用代码更改值时,需要手动调用
callme()
。因此,您需要一种不同的方式来触发函数。但是,由于我不知道eclipse
{position.layers}
如何更改value属性,因此我不确定在没有更多上下文的情况下可以挂接哪个事件。我假设Java标记是由于使用eclipse jee作为开发工具。感谢大家的回答。实际上,我改变了解决方案——我想在JavaScript函数中做什么——现在我在Java中做这件事,并得到了回报。
 var element = document.getElementById('abc');
 var event = new Event('change');
 element.dispatchEvent(event);