自定义函数参数传递为字符串格式时

在小程序中,自定义函数参数传递为字符串格式时,下面自写3种方法: 
①:采用this传递 
②:引号缺省 
③:转义字符(html中 &quot 代表"双引号,JScript中直接\" 和Java通用转义字符集) 

<html> 
<head> 
    <script language="LiveScript"> 
         function pushbutton(arg){ 
             alert("嗨!你好, "+arg); 
    } 
</script> 
</head> 
<body> 
<form> 
   <input type="button" name="Button1" value="Push me" onclick="pushbutton(this.str)" str="字符串"> 
  <br><br> 
  <input type="button" name="button2" value="clicl me" onclick=pushbutton("字符串")> 

<br><br> 
  <input type="button" name="Third" value="Third" onclick="pushbutton (&quot字符串&quot)"> 

  </form> 
</body> 
</html>

猜你喜欢

转载自my.oschina.net/u/3679192/blog/1612475