jQuery将内容加载到div中的问题

时间:2011-05-12 09:37:58

标签: jquery

$("body *").live('mouseover', function() {
    var currentId = $(this).attr('id');
    var html = "<div id='perfect4' style='font-size:10px;'><div id='pos1'><br>ID: " +currentId+ 
        " <br>Klasse: " +currentClass+ " </div><div id='pos' style='width:300px'></div></div>";
    $("#perfect4").html(html).replacewith(html);
});

在ff中有效,因为有错误(replacewith) 我知道,replaceWith是正确的 但没有这个,它就行不通了

不起作用:

$("#perfect4").html(html)

为什么?

1 个答案:

答案 0 :(得分:0)

你不应该在元素中插入html,而只是做

$("body *").live('mouseover', function() {
  var currentId = $(this).attr('id');
  var html = "<div id='perfect4' style='font-size:10px;'><div id='pos1'><br>ID: " +currentId+ 
    " <br>Klasse: " +currentClass+ " </div><div id='pos' style='width:300px'></div></div>";
  $("#perfect4").replacewith(html);    // without the .html() call
});

(假设您已经开始使用'#perfect4'元素)