Javascript 我需要有一个监听器,当输入在js中获得值时使用
我的页面中有输入,它从js中的其他函数获取或设置值 现在我想知道,当我的输入获取或设置值时,它运行其他任何方式Javascript 我需要有一个监听器,当输入在js中获得值时使用,javascript,jquery,Javascript,Jquery,我的页面中有输入,它从js中的其他函数获取或设置值 现在我想知道,当我的输入获取或设置值时,它运行其他任何方式 function and set other input value here is my function set value to input1 function showPoint(loc) { var docloc = myDiagram.transformDocToView(loc); var elt = document.getElementById(
function and set other input value
here is my function set value to input1
function showPoint(loc) {
var docloc = myDiagram.transformDocToView(loc);
var elt = document.getElementById("P18_LOC");
elt.value = "view coordinates: " + docloc.x.toFixed(2) + " " + docloc.y.toFixed(2);
}
现在,当输入get或set value运行其他函数时,我需要任何事件或侦听器
我厌倦了onchange()
和oninput()
以及更多的js事件,但我无法修复它
现在:有什么方法可以做到这一点吗?当元素通过代码动态更改其值时,像
change
和input
这样的用户事件不会触发。您需要做的是使用jQuery方法手动调用这些事件
function showPoint(loc) {
var docloc = myDiagram.transformDocToView(loc);
var elt = document.getElementById("P18_LOC");
elt.value = "view coordinates: " + docloc.x.toFixed(2) + " " + docloc.y.toFixed(2);
// Trigger the change event of the P18_LOC element
$(elt).trigger("change");
}
现在,您可以为P18\u LOC设置一个change
事件处理程序,它将在调用showPoint()
时触发