WEB开发网
开发学院网页设计JavaScript <img usemap不能得到outHTML,如何对标签操作 阅读

<img usemap不能得到outHTML,如何对标签操作

 2012-05-25 11:12:27 来源:WEB开发网   
核心提示: HTML代码: <div id="img01" class="x-hide-display"> <map id="jfreechart-5656490627055919439.png" name="jfreechar

 HTML代码:

   <div id="img01" class="x-hide-display">
      <map id="jfreechart-5656490627055919439.png" name="jfreechart-5656490627055919439.png">
<area shape="poly" coords="522,269,525,275,519,275,519,275" title="(xxx费用, xxxx年) = 44,368,022.12" alt="" nohref="nohref"/>
<area shape="poly" coords="525,542,525,544,522,545,520,544,519,542,520,540,522,539,525,540,525,542,525,542" title="(xxx总费用, xxxx年) = 677,419.99" alt="" nohref="nohref"/>
<area shape="poly" coords="519,265,525,265,525,271,519,271,519,265,519,265" title="(总费用, xxxx年) = 45,045,442.11" alt="" nohref="nohref"/>
<area shape="poly" coords="343,69,346,75,340,75,340,75" title="(xxxxx总费用, 2011年) = 76,801,537.89" alt="" nohref="nohref"/>
<area shape="poly" coords="346,535,345,537,343,538,341,537,340,535,341,533,343,532,345,533,346,535,346,535" title="(xxx总费用, xxxx年) = 1,849,360.877" alt="" nohref="nohref"/>

<area shape="poly" coords="340,58,346,58,346,64,340,64,340,58,340,58" title="(总费用, xxxx年) = 78,650,898.767" alt="" nohref="nohref"/>
<area shape="poly" coords="164,492,167,498,161,498,161,498" title="(xxx总费用, 2010年) = 8,237,826.64" alt="" nohref="nohref"/>
<area shape="poly" coords="167,544,166,546,164,547,162,546,161,544,162,542,164,541,166,542,167,544,167,544" title="(xx总费用, xxxx年) = 341,959.202" alt="" nohref="nohref"/>
<area shape="poly" coords="161,490,167,490,167,496,161,496,161,490,161,490" title="(总费用, xxxx年) = 8,579,785.842" alt="" nohref="nohref"/>
</map>

				  	  <img class="changeOutHTML"  src="/servlet/DisplayChart?filename=jfreechart-5656490627055919439.png" width="600" height="600" border=0 usemap="#jfreechart-5656490627055919439.png">	
	  
    </div>

问题:如何在<img>标签的前后加上<center></center>包裹
第一个想到的方法就是outHTML嘛,这个一定行,但是我在FF上尝试去得到,但返回的都是undefined,(IE上没有测试过),就算可以那也不兼容FF,所以没有测试

下面是如何解决这个问题的:

这个就是完成居中的代码:

JS代码

var imgs=document.getElementsByTagName('div');
		var imgsFilters=new Array();
		for(var i=0;i<imgs.length;i++){
			if(/^img/.test(imgs[i].id)){
				imgsFilters.push(imgs[i]);
			}
		}
		//循环替换
		for(var i=0;i<imgsFilters.length;i++){
			var tag=imgsFilters[i].innerHTML.replace(/(\n|\r|(\r\n)|(\u0085)|(\u2028)|(\u2029))/g, ""); 
			var patt = new RegExp("<img.*>","g");
			var result=patt.exec(tag);
            tag=tag.replace(result,"<center>"+result+"</center>");
            imgsFilters[i].innerHTML=tag;
		}

1 2  下一页

Tags:lt img usemap

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接