code=JScript]document.getElementById("zhang").innerHTML.substr(0, 2).style.color = col[i] col[0] = '#FFFFFF'; [/code]
<div id="zhang" onclick="Over()">abcdeggsdf></div>
我想更改id为 zhang的 div层的里边值的前2个 即abcdeggsdf中的ab的颜色为某一颜色 要怎么搞
------解决方案--------------------
- HTML code
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <style> </style> </head> <body> <div id="zhang" onclick="Over(this)">abcdeggsdf></div> <script> function Over(o){ o.innerHTML = '<span style="color:red;">'+o.innerHTML.substring(0,2)+'</span>'+o.innerHTML.substring(2, o.innerHTML.length); } </script> </body> </html>