我试图控制是否在此处输入文本是我的代码,但它不起作用,我找不到问题所在
<html>
<head>
<script type="text/javascript">
function CheckInfos()
{
var x=document.forms("name").value;
if(x==null)
{
alert("adınızı kontrol ediniz");
}
}
</script>
</head>
<body>
<input type="text" id="name" />
<input type="button" value="test" onclick="CheckInfos()"/>
</body>
最佳答案
不要使用“name”作为 ID,而使用 getElementById。
var value = document.getElementById("foo").value;
但是你应该使用表格:
<form name="myform" action="?" method="get" onsubmit="return CheckInfos(this)">
<input type="text" name="foo" />
<input type="submit" value="test"/>
</form>
<script>
function CheckInfos(form) {
if (form.elements.foo.value == "") {
alert("error");
}
return false;
}
</script>
关于javascript - 检查是否输入了文本。找不到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9500780/