我有html文本框,但是当我点击提交时,它没有显示3个
<script type="text/javascript">
function readBox() {
var phone = document.getElementById('phone').value;
var email = document.getElementById('email').value;
alert("You typed " + email, + age, + tShirt);
}
</script>
为什么这不起作用的任何想法?
<form name="readBox" action="/">
<label>Age:</label>
<input type="text" id="age" name="age">
<label>T-Shirt Size:</label>
<input type="text" id="tShirt" name="tShirt">
<label>Email Address:</label>
<input type="text" id="email" name="email">
<br />
<input type="submit" style="display: inline-block;" onClick="readBox()">
答案 0 :(得分:1)
假设您只获得"You typed " + email
alert("You typed " + email + age + tShirt);
你有很多逗号。此外,您没有任何ID为phone
的元素,并且未定义tShirt
变量。
答案 1 :(得分:0)
我认为它不会仅仅转到函数readBox。要在onclick上执行的表单名称和函数名称是相同的。这就是它造成问题的原因。
更改您的表单名称,它应该转到该功能。
这里有一些对我有用的东西: - HTML
<form action="/">
<label>Age:</label>
<input type="text" id="age" name="age">
<label>T-Shirt Size:</label>
<input type="text" id="tShirt" name="tShirt">
<label>Email Address:</label>
<input type="text" id="email" name="email">
<br />
<input type="submit" style="display: inline-block;" onclick="readBox()">
</form>
的Javascript
function readBox() {
var age = document.getElementById('age').value;
var email = document.getElementById('email').value;
alert("You typed " + email +" "+ age);
}
答案 2 :(得分:0)
更改脚本的功能名称
function read(){
var email = document.getElementById('email').value;
var age = document.getElementById('age').value;
var tShirt = document.getElementById('tShirt').value;
alert("You typed " + email +","+ age+"," + tShirt);
}
`
<form name="readBox">
<label>Age:</label>
<input type="text" id="age" name="age">
<label>T-Shirt Size:</label>
<input type="text" id="tShirt" name="tShirt">
<label>Email Address:</label>
<input type="text" id="email" name="email">
<br />
<input type="button" style="display: inline-block;" onClick="read()" value="submit">