.attr 选择器不会在每个循环中工作?

Gab*_*ciu 0 javascript jquery

这是代码:

  $.ajax({
      url: 'AEWService.asmx/previewAsset',
      type: "GET",
      contentType: "application/json; charset=utf-8",
      data: json,
      success: function (json) {
          var prevObj = jQuery.parseJSON(json.d);
          setInterval(function () {
              var pId = $('#previewIframe').contents().find('[preview-id]');
              $.each(prevObj, function (i, item) {
                  pId.each(function () {
                      var pElem = this.attr("preview-id");
                      if (pElem == item.Id) {
                          $(this).html(item.Value);
                      }
                  });
              });
          }, 3000);
      }
  });
Run Code Online (Sandbox Code Playgroud)

Fel*_*ing 5

this是一个 DOM 节点,而不是一个 jQuery 对象。请阅读.each()文档并查看示例。

实际上,您似乎已经知道这一点,因为您正在调用$(this).html()...