该小程序中,自定义函数参数传递为字符串格式时,下面自写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>
①:采用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>