我创建了下面的函数来识别每次页面加载时动态生成的 onclick 事件。我能够将 onclick 事件放入变量中(开发人员控制台输出如下所示)。我想执行 onclick 事件,但找不到一个好的方法。如有任何帮助,我们将不胜感激。
“f onclick(事件){ mstrmojo.dom.captureDomEvent('*lK1129*kWA92AF1C396244F28902B3171F9642E57*x1*t1530820506700','点击', self, 事件) }"
function applyAll() {
//Get the self Link to click it
var linkBys = document.getElementsByClassName("mstrmojo-DocTextfield-valueNode");
// loop through each result
for(y = 0;y < linkBys.length;y++){
// retrieve the current result from the variable
var linkBy = linkBys[y];
// check the condition that tells me this is the one I'm looking for
if(linkBy.innerText.indexOf("link") !== -1){
// Find the right class
var idy = document.getElementsByClassName("mstrmojo-DocTextfield-valueNode")[y].onclick;
console.log(idy);
}
}
}
最佳答案
如果属性“onclick”被定义为函数,则可以将其作为函数运行。
var idy = document.getElementsByClassName("")[y].onclick();
你也可以用另一种方式处理:
var idy = document.getElementsByClassName("")[y].onclick;
idy();
关于Javascript执行存储在变量中的onclick事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51199122/