简体   繁体   English

第二次调用javascript click()方法不起作用

[英]Second call to javascript click() method doesn't work

I have a problem when calling this function: 调用此函数时出现问题:

function dobleevent(obj){
    if (document.total.motivo.value){
       document.total.resumen.click();
       document.total["modificar"][0].click();      
    } else{
       alert("TextArea Empty");
       return false;
    }
}

With this HTML: 使用此HTML:

<input class="boton1" name="modificar"
  type="button" id="modificar" value="Modificar"
  onclick="dobleevent(this);">

The problem is that it only executes the first click method and it does not executes the next one. 问题在于它仅执行第一个click方法,而没有执行下一个click方法。 Why? 为什么?

I would really advise you to use Unobtrusive JavaScript . 我真的建议您使用Unobtrusive JavaScript That way you can make a difference between HTML and JavaScript. 这样,您就可以在HTML和JavaScript之间有所作为。

Maybe using a framework such as jQuery . 也许使用诸如jQuery之类的框架。

So it would be: 因此它将是:

HTML: HTML:

<input class="boton1" name="modificar" type="button" id="modificar" value="Modificar" />

JavaScript: JavaScript:

$('#modificar').on('click', function(){
    doSomething();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM