2011-05-12 111 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