2011-05-12 129 views
-1
$("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将是正确 ,但不这样做,它不会工作问题与jQuery内容加载到DIV

是不工作:

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

为什么?

+0

,你必须定义currentClass? – Vivek 2011-05-12 09:44:27

+0

[jQuery与.live,.mouseover和.replaceWith/.html问题]的可能重复(http://stackoverflow.com/questions/5979635/jquery-problem-with-live-mouseover-and-replacewith-html) – 2011-05-12 14:45:07

回答

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'元素开始)

+0

好吧,但它不会重新加载数据,如果我用光标 – DREAM 2011-05-12 09:58:52

+0

光标移动到文档中的另一个元素,所以这个解决方案它不工作,它应该如何工作 – DREAM 2011-05-12 10:28:53

+0

嗯,不知道? =( – DREAM 2011-05-12 11:42:59