将jQuery从1.6更新到1.7会破坏我的代码

时间:2011-12-20 22:44:52

标签: javascript jquery

我最近将jQuery从1.6更新到1.7,以下内容已停止工作:

问题:

没有更新任何元素,我的代码有什么问题吗?或者我使用的东西可能通过更新jQuery而受到影响?

JavaScript函数调用使用jQuery更新一组元素:

function NGUIM_updateCard(data)
{      
  var id = data._id;
  var deadline = data.deadline;
  var description = data.description;
  var roi = data.roi;
  var sp = data.sp;
  var value = data.value;
  var type = data.type;
  var title = data.title;
  var developers = data.developers;

  console.log(
    id + "\n" +
    deadline + "\n" +
    description + "\n" +
    roi + "\n" +
    sp + "\n" +
    value + "\n" +
    type + "\n" +
    title + "\n" +
    developers + "\n"
  );

  var developerString = "";
  for(var i = 0; i < developers.length; i++)
  {
    if(i == 0){
      developerString += developers[i] + ',';
    } else {
      developerString += developers[i];
    }
  }

  var card = $("span[data-id="+id+"]").parent().parent();
      card.find('.card-title').text(title);
      card.find('.card-description').text(description);


  card.find('.card-attributes')
      .attr('data-deadline', deadline)
      .attr('data-sp', sp)
      .attr('data-value', value)
      .attr('data-roi', roi)
      .attr('data-devs', developerString);


  card.find('.card-attr-deadline').text(deadline);
  card.find('.card-attr-value').text("Value: " + value);
  card.find('.card-attr-sp').text("SP: " + sp);
  card.find('.card-attr-roi').text("ROI: " + roi);

  if(card.hasClass("improvement")){
    if(type == "fix"){
      card.removeClass("improvement")
          .addClass(type);
    } else if (type == "story"){
      card.removeClass("improvement")
          .addClass(type);
    }
  } else if (card.hasClass("fix")){
    if(type == "improvement"){
      card.removeClass("fix")
          .addClass(type);
    } else if (type == "story"){
      card.removeClass("fix")
          .addClass(type);          
    }
  } else {
    if(type == "fix"){
      card.addClass(type);
    } else if (type == "improvement"){
      card.addClass(type);
    }
  }
}

Console.logs输出其预期值,但元素未更新。 Chrome开发者控制台中没有出现任何错误。

console.log(card);的输出:

<li class="story">
  <header>
    <h1 class="card-title">abcd</h1>
    <p class="card-attr-deadline">10/10/2010</p>
    <span class="edit-card"></span>
    <span class="card-developers"></span>
    <span class="card-attributes" data-value="5" data-roi="1.00" data-sp="5" data-deadline="10/10/2010" data-id="0WndpeAmnzWRVQw15zizanU0" data-devs="a,brownj2"></span>
  </header>
  <section class="card-description">...</section>
  <p class="card-attr-sp">SP: 5</p>
  <p class="card-attr-value">Value: 5</p>
  <p class="card-attr-roi">ROI: 1.00</p>
</li>

1 个答案:

答案 0 :(得分:2)

尝试更改

card.find('.card-attributes')
  .attr('data-deadline', deadline)
  .attr('data-sp', sp)
  .attr('data-value', value)
  .attr('data-roi', roi)
  .attr('data-devs', developerString);

card.find('.card-attributes').first()
  .data('deadline', deadline)
  .data('sp', sp)
  .data('value', value)
  .data('roi', roi)
  .data('devs', developerString);