javascript onclick功能不起作用

时间:2013-11-16 06:28:00

标签: javascript

<title>Javascript</title>
<script>
function buttonreport(id,name,address){
    var userid ="Id:"+id;
    var username="Name :"+name+"\n";
    var useraddress ="Address:"+address+"\n";
    alert(userid+username+useraddress);
}
</script>
</head>
<body>
ID:<input type="text" name="id"/><br/>
NAME:<input type="text" name="name"/><br/>
ADDRESS:<input type="text" name="address"/><br/>
<input type="submit" value="Submit" onclick="buttonreport(this.id,this.name,this.address)"/>

</body>

现在正在工作,但输出显示为id:name:地址未显示输入值

3 个答案:

答案 0 :(得分:2)

您在脚本中拼错了警告

答案 1 :(得分:0)

我不是JS专家,但也许您需要提交表单周围的<form>标签。您也可以使用getelementbyid

答案 2 :(得分:0)

您的alret应为alert。现在它有效:)

<title>Javascript</title>
<script>
function buttonreport(id,name,address){
    var userid ="Id:"+id;
    var username="Name :"+name+"\n";
    var useraddress ="Address:"+address+"\n";
    alert(userid+username+useraddress);
}
</script>
</head>
<body>
ID:<input type="text" name="id"/><br/>
NAME:<input type="text" name="name"/><br/>
ADDRESS:<input type="text" name="address"/><br/>
<input type="submit" value="Submit" onclick="buttonreport(this.id,this.name,this.address)"/>