0

我已将 div 的 html 内容复制到 javascript 中的变量中。现在我想把标题属性的值放到 TD 标签的内容中,无论哪个类作为弹出窗口。所以我创建了以下代码。但它没有帮助..

var tmpDiv = document.createElement("div");
tmpDiv.setAttribute("style","display:none");
$(tmpDiv).html($('#'+divid+" .scrollTableContainer").html());

$(tmpDiv+ 'td .popup').each(function(index,value) {
    $(this).html($(this).attr('title'));
});
4

2 回答 2

0
$(tmpDiv).find('td.popup').each(function(index,value) {
    $(this).html($(this).attr('title'));
});

在您的代码中 tempDiv 是 javascript 对象,因此 tempDiv+'td.popup' 是不允许的。其次,如果您需要找到 td 类 popup 删除 td 和 .popup 之间的空间

于 2012-12-15T14:51:22.207 回答
0

您正在尝试连接一个 DOM 对象和一个字符串来创建一个选择器。你不能连接一个字符串和一个对象

将 jQuery 用于所有代码会更有意义

var tmpDiv=$('<div>').hide().html($('#'+divid+" .scrollTableContainer").html());

tmpDiv.find('td.popup').each(function(index,value) {
    $(this).html($(this).attr('title'));
});
于 2012-12-15T14:55:27.020 回答