使用json设置tag's value属性不工作

setting tag's value property with json not working

本文关键字:value 属性 工作 json 设置 tag 使用      更新时间:2023-09-26

我有这个JS:

$.getJSON('getMessageDetails.php', function (json) { 
   var uc = json[4];
   var uc_length = uc.length;
   var firstPartLength = uc_length - 5;
   var uc_1 = uc.substring(0, firstPartLength);  
   var uc_2 = uc.substr(-5, 3);
   var uc_3 = 'RC';
   if (json[2] != old_id)
   {
      $("#td_id").text(json[2]);
      $("#td_id_new").text(json[2]);
      $("#td_subject").text(json[3]);
      $("#span_1").text(uc_1); 
      $("#span_2").text(uc_2); 
      $("#span_3").text(uc_3); 
      old_id = json[2];
   }    
 }); 
然后是php/html
 if (count($row) > 0)
 {
    echo "<input type='hidden' id='td_id_new' value='".$new_id."'></input>";   
    echo  $new_id;
    echo "<tr>";        
    echo '<td><a class="red_link" href="'.ADDRESS.'view_message.php?id='.$new_id.'"><span class="red_link" id="td_subject">'.$subject.'</span></a></td>';
    echo '<td><span id="span_1">'.$uniqueCode1.'</span><span id="span_2" class="pink_text">'.$uniqueCode2.'</span><span id="span_3">'.$uniqueCode3.'</span></td>';
    echo "</tr>";
  }

我想通过我的json $("#td_id_new").text(json[2]);

当我检查元素时,输出将$new_id作为0....当我初始化它,而不是用新的id,其他一切(所有其他标签)更新我的json

检查元素:

 <input xmlns="http://www.w3.org/1999/xhtml" type="hidden" id="td_id_new" value="0">7</input>

我得到了上面的值属性为7,因此$new_id是7,但在$new_id的标签中仍然没有任何东西?

请帮忙?谢谢你

在PHP中设置new_id=0

如果你把它拿出来,并像你说的那样初始化JSON,它应该工作