像这样是获取不到值的,弹出的消息是 underfined:
<html>
<style type="text/css">
input {
border: 1px solid #CCCCCC;
font-size: 10.5pt;
padding: 2px 3px 1px;
width: 220px;
color: #999999;
}
</style>
</head>
<body>
<input
name="myInput-keleyi-com" id="keleyiInput" type="text"
onBlur="(this.value==‘‘)?this.value=‘123456‘:this.value" onFocus="abc()"
value="123456" >
<script>
function abc(){
var x=document.getElementsByName("myInput-keleyi-com").value;
alert(x);
}</script>
</body>
</html>
应该是这样:
var x=document.getElementsByName("myInput-keleyi-com")[0].value;
或者:var x=document.getElementsById("keleyiInput").value;
getElementById是element单数,
getElementsByName是elements复数。
时间: 2024-12-18 23:12:06