我想改变INNERHTML中的值
问题是在这样的,我做了一个网页段落标签内,根据自己的需求,自动截取STRING换行的小JS程序。
但是现在问题就是,我用DOCUMENT.WRITE可以显示我的段落,但是却无法替换掉原来段落里旧的没有格式的文字,就是没反应咯,代码如下
- JScript code
<script type="text/javascript">function autoBr(max1){var maxVal=document.getElementById("right");var maxVal_Val=maxVal.childNodes.item(3);var maxVal_3=maxVal.getElementsByTagName("p")[1];var final_var=maxVal_3.innerHTML;var final_Length=maxVal_3.innerHTML.length;var temp="";while(final_Length>max1){ temp=temp+final_var.substr(0,max1)+"<br />"; final_var=final_var.substr(max1,final_Length); if(final_var.length==0) { break; } }temp=temp+"<br />"+final_var;final_var=temp;maxVal_3=maxVal_3.innerHTML.replace(/[\n]/,final_var);return maxVal_3;}function testYes(){ autoBr(15); }</script>
- HTML code
<body onload="testYes()"><div id="right"> <h3 class="title"><a href="<!--{$url_about}-->" title="More" class="more">More</a><span>公司简介</span></h3> <div class="text"> <div class="editor"> <p> <!--{if $ads_zone2}--> <!--{foreach $ads_zone2 as $volist}--> <img width="<!--{$volist.width}-->" height="<!--{$volist.height}-->" hspace="2" align="left" vspace="2" src="<!--{$volist.uploadfiles}-->" /> <!--{/foreach}--> <!--{/if}--> </p><p><!--{$config.about|filterhtml:435}-->...</p> </div> </div> <h3 class="title line"><a href="<!--{$url_product}-->" title="More" class="more">More</a><span>最新产品</span></h3> <div class="list"> <ul id="drawimg"> <!--{foreach $volist_newproduct as $volist}--> <li style="width:158px; height:183px;"> <a href="<!--{$volist.url}-->" class="imgbox"><img src="<!--{$volist.thumbfiles}-->" onload="javascript:DrawImage(this,'150','150');" alt="<!--{$volist.produtname}-->" /></a> <h4><a href="<!--{$volist.url}-->" title="<!--{$volist.productname}-->"><!--{$volist.sort_productname}--></a></h4> </li> <!--{/foreach}--> </ul> <div style="clear:both;"></div> </div><!-- #list //--> </div><!-- #right //--> <div style="clear:both;"></div> </div></body>
[解决办法]
document.getElementById("id").innerHTML="新的html";
[解决办法]