Html的javascrip脚本如何实现input的value值跟一个变量进行对比? 具体看代码 求教
<html><head><title>Hello</title><scripttype="text/javascript"><!--functionmyfunc(){//...
<html>
<head>
<title>Hello</title>
<script type="text/javascript">
<!--
function myfunc()
{
//string a="hello"
if(intger.parseints(document.myform.mytext.value)==1)
alert(OK)
//document.myform.mytext.value=document.myform.mytext.value.toUpperCase()
//alert(hello)
}
//-->
</script>
<style type="text/css">
<!--
.STYLE1 {font-family: Georgia, "Times New Roman", Times, serif}
-->
</style>
</head>
<body bgcolor="#CC6600">
<br>
<br>
<br>
<br>
<br>
<br><br>
<br>
<br><br>
<br>
<br>
<center>
<form name="myform">
<h1 class="STYLE1">Hello World </h1>
<input name="mytext" type="text" onClick="viod()" size="20" style="width:600px; height:20px">
<br>
<br>
<input type="button" onClick="myfunc()" value="收 索" style="width: 85px; height: 30px;" />
</form>
</center>
</body>
</html> 展开
<head>
<title>Hello</title>
<script type="text/javascript">
<!--
function myfunc()
{
//string a="hello"
if(intger.parseints(document.myform.mytext.value)==1)
alert(OK)
//document.myform.mytext.value=document.myform.mytext.value.toUpperCase()
//alert(hello)
}
//-->
</script>
<style type="text/css">
<!--
.STYLE1 {font-family: Georgia, "Times New Roman", Times, serif}
-->
</style>
</head>
<body bgcolor="#CC6600">
<br>
<br>
<br>
<br>
<br>
<br><br>
<br>
<br><br>
<br>
<br>
<center>
<form name="myform">
<h1 class="STYLE1">Hello World </h1>
<input name="mytext" type="text" onClick="viod()" size="20" style="width:600px; height:20px">
<br>
<br>
<input type="button" onClick="myfunc()" value="收 索" style="width: 85px; height: 30px;" />
</form>
</center>
</body>
</html> 展开
1个回答
展开全部
Javascript是根据id获取对象,所以在input标签里加上属性,方便获取input对象
html:
<input id="myText" name="mytext" type="text" onClick="viod()" size="20" style="width:600px; height:20px">
javascript:
var inputValue = document.getElementById("myText").value;
var targetValue = "xxx";
if(input value == targetValue) {
//do something
}else {
//do something
}
html:
<input id="myText" name="mytext" type="text" onClick="viod()" size="20" style="width:600px; height:20px">
javascript:
var inputValue = document.getElementById("myText").value;
var targetValue = "xxx";
if(input value == targetValue) {
//do something
}else {
//do something
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询