藍森林首頁 | 返回主頁 | 本站地圖 | 站內搜索 | 聯繫信箱 |
 您目前的位置:首頁 > 自由軟件 > 技術交流 > 應用編程


    

藍森林 http://www.lslnet.com 2006年8月25日 8:28

請教一個Javascript問題

在一本書的一個例子中有如下部分內容:
function display(triplet){
        document.bgColor ='#'+triplet
        alert('Background color is now '+ triplet)
}
然後在另一個函數中有如下一句:
document.write ('<a href="javascript:Display(\"+(red+green+blue)+'\')">')
瀏覽器一運行,當然是網頁有錯誤,我也知道這一句有錯,但不知該怎麼改.請教各位,有誰知道,請告知.謝謝!

[html]<script>
function display(triplet){
    document.bgColor ='#'+triplet
    alert('Background color is now '+ triplet)
}
document.write ('<a href="javascript:display(\'006699\')">test</a>')
</script>
[/html]

red,green,blue
為變量名,如果沒有定義就錯了!

還有應是這樣寫
document.write ('<a href="javascript: display(\''+(red+green+blue)+'\')">'

謝謝panliu888!代碼已經正確,但我不明白這兩個"\"的含義?希望能告知.謝謝!

實現轉義字符呀!!
因為字符串用 ' 來括起來!所以字符串裡的 ' 就要加入 \ 來轉義呀!




Copyright © 1999-2000 LSLNET.COM. All rights reserved. 藍森林網站 版權所有。 E-mail : webmaster@lslnet.com