javascript自訂函數參數傳遞為字串格式,javascript字串

來源:互聯網
上載者:User

javascript自訂函數參數傳遞為字串格式,javascript字串

自訂函數參數傳遞為 字串格式 ,傳遞方式
1:用this傳遞
2:引號預設
3:逸出字元(html中 " 代表"雙引號,'代表單引號,javascript中直接\" 和Java通用逸出字元集)

<html> <head> <script language="LiveScript"> function print(arg){ alert("你好!"+arg); } </script> </head> <body> <form> <input type="button" name="Button1" value="first" onclick="print(this.str)" str="你好one"> <br><br> <input type="button" name="button2" value="second" onclick=print("你好two")> <br><br> <input type="button" name="button3" value="Third" onclick="print ("你好three")"> </form> </body> </html>

javascript函數的參數為複雜的字串

如果使用這樣的形式:
setTimeout("moveElement()",interval);

那麼moveElement()將是作為一個13個字元的字串,而不是作為它所代表的函數值本身。所以必須先用引號結束前面的字串,然後用加號串連moveElement()所代表的函數值。
王磊[權威專家]

javascript字串參數傳遞

<%
str = "aaa"
response.write("<a href="& chr(34) &"javascript:del('"& rs("name")&"')"& chr(34) &"> 刪除 </a>") %>

del()這個方法如果直接寫del(str)這樣就表示參數為變數str的值,
del("str")或del('str')表示參數為字串為"str"
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.