繁体   English   中英

无法使用JQuery添加ID标签

[英]Cannot add Id tag using JQuery

我想添加一个自定义的id标记,例如id = keys[key][each]作为要追加到new_resumes类的html的一部分,例如,我想要

<div class = "filtered_results" id = keys[key][each] ...

而是使用下面的代码-当我使用attrprop标签时,它将为新的履历表类添加一个ID。 我欣赏我的代码不是最好的。

for (var key in keys) {
    $(".new_resumes").append("<div class='filtered_results' style='color:white; background-color:red; text-align:center; height:20px; line-height: 20px'>" + key + "</div>");
    for (var each in keys[key]) {
        $(".new_resumes").append("<div class='filtered_results' style ='height:60px; text-align:center; height:60px; line-height: 60px;'>" + keys[key][each][0] + "</div>").prop('id',keys[key][each][0]);

如果我理解您的问题,是否要将ID添加到要创建的filtered_results div中?

您应该像这样串联它:

$(".new_resumes").append("<div class='filtered_results' id='" +keys[key][each][0] +"' style ='height:60px; text-align:center; height:60px; line-height: 60px;'>" + keys[key][each][0] + "</div>")

注意这一部分: id='" +keys[key][each][0] +"'

现在,您正在对仍为.new_resumes元素的当前元素调用.prop

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM