在小程序中,自定义函数参数传递为字符串格式时,下面自写3种方法:
①:采用this传递
②:引号缺省
③:转义字符(html中 " 代表"双引号,JScript中直接\" 和Java通用转义字符集)
<html>
<head>
<script language="LiveScript">
function pushbutton(arg){
alert("嗨!你好, "+arg);
}
</script>
</head>
<body>
<form>
<input type="button" name="Button1" value="Push me" οnclick="pushbutton(this.str)" str="字符串">
<br><br>
<input type="button" name="button2" value="clicl me" οnclick=pushbutton("字符串")>
<br><br>
<input type="button" name="Third" value="Third" οnclick="pushbutton ("字符串")">
</form>
</body>
</html>
转载于:https://my.oschina.net/u/3679192/blog/1612475