开发者

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 requ开发者_如何学JAVAire 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(){
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜