简体   繁体   中英

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:

<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. Why?

I would really advise you to use Unobtrusive JavaScript . That way you can make a difference between HTML and JavaScript.

Maybe using a framework such as jQuery .

So it would be:

HTML:

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

JavaScript:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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