我想做的共能是:输入正则表达式 网页中如果符合的话就 高亮显示。 我先能 根据输入的正则 找到相应的字符串。 但是怎么让他高亮呢? 比如:
<html>
<head>
<title>无标题页</title>
<script>
</head>
<body>
<form id="form1" runat="server">
<a href="http://paper.wenweipo.com/2012/05/16/CH1205160004.htm" >高亮1</a>
<a href="http://paper.wenweipo.com/2012/05/16/CH12051655555504.htm" >高亮2</a>
<a href="http://paper.wenweipo.com/2012/05/16/CH120516666666604.htm" >高亮3</a> </form>
</body>
我用这个正则http://paper.wenweipo.com/2012/05/16/.+.htm是可以找到
http://paper.wenweipo.com/2012/05/16/CH1205160004.htm
http://paper.wenweipo.com/2012/05/16/CH12051655555504.htm
http://paper.wenweipo.com/2012/05/16/CH120516666666604.htm
但是我怎么才能让 高亮1 高亮2 高亮3 这三个字符亮呢?
<html>
<head>
<title>无标题页</title>
<script>
</head>
<body>
<form id="form1" runat="server">
<a href="http://paper.wenweipo.com/2012/05/16/CH1205160004.htm" >高亮1</a>
<a href="http://paper.wenweipo.com/2012/05/16/CH12051655555504.htm" >高亮2</a>
<a href="http://paper.wenweipo.com/2012/05/16/CH120516666666604.htm" >高亮3</a> </form>
</body>
我用这个正则http://paper.wenweipo.com/2012/05/16/.+.htm是可以找到
http://paper.wenweipo.com/2012/05/16/CH1205160004.htm
http://paper.wenweipo.com/2012/05/16/CH12051655555504.htm
http://paper.wenweipo.com/2012/05/16/CH120516666666604.htm
但是我怎么才能让 高亮1 高亮2 高亮3 这三个字符亮呢?
<html>
<head>
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<a href="http://paper.wenweipo.com/2012/05/16/CH1205160004.htm" >高亮1</a>
<a href="http://paper.wenweipo.com/2012/05/16/CH12051655555504.htm" >高亮2</a>
<a href="http://paper.wenweipo.com/2012/05/16/CH120516666666604.htm" >高亮3</a> </form>
<script>
function $(el){
return typeof el == 'string' ? document.getElementById(el) : el;
}
function $t(name, cot){
cot = cot || document;
return cot.getElementsByTagName(name);
}
var s = 'http://paper.wenweipo.com/2012/05/16/.+.htm';
var r = new RegExp(s);
var objs = $t('a', $('form1'));
for( var i = 0, len = objs.length; i < len; i++){
if( r.test(objs[i].href) ){
objs[i].innerHTML = '<span style="color:red;">'+objs[i].innerHTML+'</span>';
}
}
</script>
</body>
这个意思?
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<form id="form1" runat="server">
<a href="http://paper.wenweipo.com/2012/05/16/CH1205160004.htm" id="url1" ><span id="power1" >高亮1</span></a>
<a href="http://paper.wenweipo.com/2012/05/16/CH12051655555504.htm" >高亮2</a>
<a href="http://paper.wenweipo.com/2012/05/16/CH120516666666604.htm" >高亮3</a> </form> <script>
var oa= document.getElementById("url1");
if(oa.href=="http://paper.wenweipo.com/2012/05/16/CH1205160004.htm"){ document.getElementById("power1").style.color="yellow"; }
</script> </body>
</html>
(暗夜げ螃蟹) 没有id的时候怎么办 。
(calmcrime) 能不 能改下 在输入 高亮1 的时候也 可以呢? 要怎么改 ? 改哪里呢?
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body> <form id="form1" runat="server">
<a href="http://paper.wenweipo.com/2012/05/16/CH1205160004.htm" ><span id="power1" >高亮1</span></a>
<a href="http://paper.wenweipo.com/2012/05/16/CH12051655555504.htm" >高亮2</a>
<a href="http://paper.wenweipo.com/2012/05/16/CH120516666666604.htm" >高亮3</a> </form>
<script type="text/javascript">
var thisURL= document.links;
if(thisURL!=null&&thisURL!=""){
for(var i=0;i<thisURL.length;i++){
if(thisURL[i]=="http://paper.wenweipo.com/2012/05/16/CH1205160004.htm"){
document.getElementById("power1").style.color="red";
}
}
}
</script>
</body>
</html>
2、高亮就是加不同颜色,说白了动态改变style 。http://www.happyalaric.com 个人技术博客