Welcome to Delicate template
Header
Just another WordPress site
Header

使用js去掉id里面的a标签并输出

6月 10th, 2011 | Posted by 无 名 in js

用js去掉某容器id里面的a标签,并输出。
代码如下:

<script type="text/javascript">
<!--
function(mid){
	var obj = document.getElementById(mid).innerHTML;
	//obj = obj.replace(/\<[\d\D]*?\>/g,"");//去掉mid里面的所有<>标签
	obj = obj.replace(/<a (.+?)>(.*?)<\/a>/ig,"$2");//去掉mid里面的<a>标签
	//alert(obj);
	document.getElementById(mid).innerHTML = obj;
	//document.getElementById(mid).className = "box_left_navtitc";//改变mid的class样式
	}
-->
</script>

注意:document.getElementById(mid)一定要在命名id的后面,否则会捕获不到,会提示错误:“消息: ‘document.getElementById(…)’ 为空或不是对象”

You can follow any responses to this entry through the RSS 2.0 Both comments and pings are currently closed.