如:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>隔字换样式</title>
<style type="text/css">
.s_text {
font-family: Verdana, Geneva, sans-serif;
}
.d_text {
font-family: MS Serif, New York, serif;
}
</style>
</head><body>
<span class="s_text">J</span><span class="d_text">a<span class="s_text">v</span><span class="d_text">a</span></span><span class="s_text">s</span><span class="d_text">c</span><span class="s_text">r</span><span class="d_text">i</span><span class="s_text">p</span><span class="d_text">t</span><span class="s_text">教</span><span class="d_text">程</span>
</body>
</html><span class="s_text">J</span><span class="d_text">a<span class="s_text">v</span><span class="d_text">a</span></span><span class="s_text">s</span><span class="d_text">c</span><span class="s_text">r</span><span class="d_text">i</span><span class="s_text">p</span><span class="d_text">t</span><span class="s_text">教</span><span class="d_text">程</span>
上面这段如何用js实现

解决方案 »

  1.   

    每个字用一个span标签包装,每个span随机对应一个class, 这些class的样式都不同就形成了随机了。产生随机数的函数 (Math.random()*样式数 + 起始值)
      

  2.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>隔字换样式</title>
    <style type="text/css">
    .s_text {
        font-family: Verdana, Geneva, sans-serif;
    }
    .d_text {
        font-family: MS Serif, New York, serif;
    }
    </style>
    </head>
    <body>
    <div id="test">Javascript教程</div>
    <script>
    function $(o){return document.getElementById(o)}
    var obj = $('test').innerHTML;
    var re = /(.)/g;
    var flg = ['s','d'];
    var i = 0;
    obj = obj.replace(re,function($){
    i = i ? 0 : 1;
    return '<span class="'+flg[i]+'_text">'+$+'</span>';
    });
    $('test').innerHTML = obj;
    </script>
    </body>
    </html>楼主 这个意思?