$("body *").live('mouseover', function() {
var currentId = $(this).attr('id');
var html = "<div id='perfect' 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);
});
不起作用 为什么
答案 0 :(得分:0)
使用选择器“body *”,你的目标是身体的所有孩子。我想你会尝试这个(删除perfect4):
$("body").bind('mouseover', function(e) {
var domTarget = e.target; // e.target grabs the node that triggered the event.
var currentId = domTarget.id;
var sHtml = "<div id='perfect' style='font-size:10px;'><div id='pos1'><br>ID: " +currentId+ " <br>Klasse: " +currentClass+ " </div><div id='pos' style='width:300px'></div></div>";
var jPerfect = $("#perfect4");
jPerfect.after(sHtml );
jPerfect.remove();
});
在perfect4中替换innerHTML:
$("body").bind('mouseover', function(e) {
var domTarget = e.target; // e.target grabs the node that triggered the event.
var currentId = domTarget.id;
var sHtml = "<div id='perfect' style='font-size:10px;'><div id='pos1'><br>ID: " +currentId+ " <br>Klasse: " +currentClass+ " </div><div id='pos' style='width:300px'></div></div>";
$("#perfect4").html(sHtml);
});
答案 1 :(得分:-1)
你可以用这个:
$("#perfect4").text(html);
或
$("#perfect4").val(html);
或
$("#perfect4").html(html);