'这个'的属性对象在$ .each中显示未定义

时间:2015-09-09 08:34:43

标签: jquery each

这里是jsFiddle:http://jsfiddle.net/6eqMn/524/

JS 部分:

$("#divProcedureCodes").append("<TABLE><TBODY><TR ID='divtr2' STATUS='Map'><TD STYLE='WIDT`enter code here`H: 20px'></TD></TR></TBODY></TABLE>");

function allChargesMapped() {
    var retval = true;   
        $.each($("#divProcedureCodes tr"), function (index, value) {
        if (this.status == "Map") {
            retval = false;
            return false;
        }
    });
    return retval;
}
var ret = allChargesMapped();
alert(ret);
alert(document.getElementById("divtr2").getAttribute("status"));

HTML 部分:

<DIV ID="divProcedureCodes"> </DIV>

1 个答案:

答案 0 :(得分:0)

使用getAttribute()功能。你不能像通常的属性那样以通常的方式得到它。

this.getAttribute('status')

    var aq = $("#divProcedureCodes tr");
    $("#divProcedureCodes").append("<TABLE><TBODY><TR ID='divtr2' STATUS='Map'><TD STYLE='WIDTH: 20px'></TD></TR></TBODY></TABLE>");

    function allChargesMapped() {
      var retval = true;
      $.each($("#divProcedureCodes tr"), function(index, value) {
        alert(this.getAttribute('status'));
        if (this.getAttribute('status') == "Map") {
          retval = false;
          return false;
        }
      });
      return retval;
    }
    var ret = allChargesMapped();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<DIV ID="divProcedureCodes"></DIV>