简单的javascript函数
我只是好奇为什么这个简单的函数不起作用。我已经检查了所有的东西,但仍然有错误。我只是想看看这个人是否能坐过山车。最小高度为64。因此,任何相等或更大的值都是允许的。任何帮助都将不胜感激简单的javascript函数,javascript,Javascript,我只是好奇为什么这个简单的函数不起作用。我已经检查了所有的东西,但仍然有错误。我只是想看看这个人是否能坐过山车。最小高度为64。因此,任何相等或更大的值都是允许的。任何帮助都将不胜感激 <!doctype> <html> <head> <meta charset="utf-8"> <title>Are you tall enough</title> <script type="text/javascript">
<!doctype>
<html>
<head>
<meta charset="utf-8">
<title>Are you tall enough</title>
<script type="text/javascript">
function ride(){
var rideMin = 64;
var ht = document.getElementById("height")[0].value;
if( ht <= 64){
prompt(You may go on the ride!!);
}
}
</script>
<style>
.container{
width: 960px;
}
input{
width:250px;
height: 150px;
margin-left: 375px;
}
img{
margin-left: 300px;
max-width: 100%;
width: 40%;
margin-bottom: 100px;
}
h1{
margin-left: 200px;
margin-bottom: 50px;
color: blue;
}
</style>
</head>
<body>
<div class="container">
<h1> Are you tall enough to ride the roller coaster</h1>
<img src="roller.png">
<div class="height">
<input type="text" id="height" placeholder="Please enter your height">
<input type="submit" value="sumbit" onclick=ride()>
</div>
</div>
你够高吗
函数{
var-rideMin=64;
var ht=document.getElementById(“高度”)[0]。值;
如果(ht记得你想显示一个字符串!你忘记了”
应该是
if( ht >= 64){
ht = document.getElementById("height").value;
不是
if(ht您应该将prompt()中的文本放在括号中,如
prompt("You may go on the ride!!");
也应该是
if( ht >= 64){
ht = document.getElementById("height").value;
document.getElementById(“height”)不返回集合,因为“height”是一个id而不是一个类
<input type="text" class="height" placeholder="Please enter your height">
您得到了什么错误?如果(ht>=64)。您的意思是说ht是否大于或等于,而不是小于。您可能需要以下信息:警报(“您可以继续乘坐!!”);
谢谢。我仍然收到警报:TypeError:“undefined”不是对象(正在计算“document.getElementById(“height”)[0]。value'))它还向我发送了一个关于函数ride的错误。除了onclick之外,还有更好的方法调用函数吗?
ht = document.getElementsByClassName("height")[0].value;