简体   繁体   中英

add click function with jQuery not work

the js code is here

 var s = "<a id='clickmodifybasic'>修改</a>"

  $("#basicinfoerrordlg").html(s);
  $("#clickmodifybasic").click(modifybasicinfo);
  $("#basicinfoerrordlg").dialog("open");
  return false;

it work well on chrome,but not good in IE8. I got similar error before. I get the following code from the develop tool of IE8. <A id=clickmodifybasic jQuery1289741833331="94">修改</A>

Assuming that you have a modifyBasicinfo() function already defined, try this code.

 var s = "<a id='clickmodifybasic'>修改</a>";

  $("#basicinfoerrordlg").html(s);
  $("#clickmodifybasic").click(function() { modifybasicinfo(); });
  $("#basicinfoerrordlg").dialog("open");
  return false;

Don't forget your ";" delimiter after you variable declaration, I have added this in for you. Hope this helps.

@WangXing, I have just tested in IE8 with this exact code:

<script type="text/javascript">
function ModifyBasicInfo()
{
    alert("clicked");
}

$(function() {
    var s = "<a id='clickmodifybasic'>קישור</a>"
    $("#basicinfoerrordlg").html(s);
    $("#clickmodifybasic").click(ModifyBasicInfo);
});
</script>
<div id="basicinfoerrordlg"></div>

It worked fine, and alert appeared when clicking the link so the problem must be with the dialog plugin you're using. What plugin is this exactly? Can you post link so we can reproduce this behavior?

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