请教一个正则表达式,如何写去除<img ........>中的宽和高

来源:百度知道 编辑:UC知道 时间:2024/06/27 12:29:11
例<P align=center><IMG src="00098.jpg" height=370 width=510></P>
<P align=center><IMG height=375 alt=22222.jpg src="00099.jpg" width=500></P>
用正则表达式给变成
<P align=center><IMG src="00098.jpg"></P>
<P align=center><IMG alt=22222.jpg src="00099.jpg"></P>
谢谢了
你的那种方法有些地方不可行啊,比如我里面有一个表格那宽和高不是也没有了,还有就是我要固定图片不要超过一定范围例:
<IMG src="aaa.jpg" onload='javascript:if(this.height>this.width){this.height=83}else{this.width=107}' height=10 width=10>
那js里面的宽和高不是也没有了

<body onload=st()>

<div id="str">

<P align=center><IMG src="00098.jpg" height=370 width=510></P>
<P align=center><IMG height=375 alt=22222.jpg src="00099.jpg" width=500></P>
</div>
<script type="text/javascript">
function st()
{
var e=document.getElementById("str");
var str1=e.innerHTML;
str1 = str1.replace(/height=\d+/g,"");
str1 = str1.replace(/width=\d+/g,"");
e.innerHTML=str1;
}
</script>
-----------------------------------
这个容易
<body onload=st()>

<div id="str">

<P align=center><IMG src="00098.jpg" height=370 width=510></P>
<P align=center><IMG height=375 alt=22222.jpg src="00099.jpg" width=500></P>
<IMG src="aaa.jpg"