日期:2014-05-16  浏览次数:20313 次

replace替换不正常
<div id="userinfo1_m_template1" style="display: none;">
<span class="line0{$Id}">&nbsp;</span>
<table width="100%">
<tr>
<td class="font">
<span class="ecolor01">*</span><b>姓名</b>
<input id="Name{$Id}" style="width: 100px;" />
</td>
</tr>
</table>
</div>

  var num=1;
  var template =$('userinfo1_m_template1');
  var templatestr=template.innerHTML;
  templatestr=templatestr.replace("\{\$Id\}",num);
但我发现替换后{$Id}已被num替换,但第二个{$Id}却未被替换

------解决方案--------------------
templatestr=templatestr.replace(/\{\$Id\}/img,num); 
这样看看
------解决方案--------------------
templatestr=templatestr.replace(/\{\$Id\}/gi,num);
------解决方案--------------------
2楼正角,m表示多行,g是全局,i是大小写