好像能用……
-----------------------------------
<html>
<head><style>.a{color:#0f0;} .b{color:#f00;}</style></head>
<body>
<div id="ha">ABCDEFG</div>
<input id="txt" value="" type="text" onkeyup="checkit(this)">
<script>
var h = document.getElementById("ha").innerHTML;
function checkit(obj){
var s = obj.value;
var r = "";
var i;
for(i=0;i<h.length && i<s.length;i++){
if(h.substring(i,i+1) == s.substring(i,i+1)){
r += '<span class="a">' + h.substring(i,i+1) + '</span>'
}
else{
r += '<span class="b">' + h.substring(i,i+1) + '</span>'
}
}
if(i<h.length){
r += h.substring(i);
}
document.getElementById("ha").innerHTML = r;
}
</script>
</body>
</html>
丁学
|
专家六级
|园豆:18730
|
2008-04-16 07:10