简体   繁体   中英

Jquery in javascript function require two clicks

I wrote a simpe inline edit using jquery. The plugin work very well, but i have a problem when i call the script within a javascript function, it require 2 click to activate the plugin. Does anyone know a way to solve this issue.. i want it in one click. Thanks in advance.

<a onclick="update(1)"> Let's update<a/>

  function update(id)
  {
  $("#edit" + id).kb_edit();   
  }

If the functionality in the plugin requires the click event handler that you're setting up inside, then that means it won't be set up until you run .kb_edit() .

So the first click runs .kb_edit() , which sets up the click handler.

Then the second click actually gets to trigger whatever was set up by the first click.

well for starters you could clean it up a little by NOT using the onclick...

<a id="myAnchor">Let's update</a>

$(document).ready(function() {
   $("#myAnchor").click(function(){
        ///put your update code here including the kb_edit code
   });
});

or if you have a series of this you can use <a class="myAnchor">...</a> and change the jquery selector:

   $(".myAnchor").click(function(){

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