首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

JS中innerHTML = "<input type='button' onclick='select()'>" onclic

2012-09-10 
JS中innerHTML input typebutton onclickselect() onclick方法不可调用script typetext/ja

JS中innerHTML = "<input type='button' onclick='select()'>" onclick方法不可调用
<script type="text/javascript">
  function change(){
   
  var str = " ";
  str += "日&nbsp期: ";
  str += "<input type='text' name='time'/>";
  str += "公司名称: ";
  str += "<input type='text' name='gsmc'/>";
  str += "<input type='button' onClick='select()' value='查询'>";
  document.getElementById("login").innerHTML = str;
  // document.getElementById("login").innerHTML = document.getElementById("select").innerHTML;
  }
   
  function select(){
  var gettime = document.getElementById("time").value;
  if(gettime == "" || gettime == null || gettime.length != 8){
  alert("请输入有效的8位数日期格式");
  return false;
  }
  }
   
  </script>
 <body>
  <div id="login">
用户名:<input type="text" name="username"/><br>
密&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="text" name="password"/><br>
<input type="button" value="登录" onClick="change()";/>
  </div>
  <div id="select" style="display: none">
  日期:<input type="text" name="time"/>
  公司名称:<input type="text" name="company"/> 
  <a href="#" onclick="select()">查询</a>
  </div>
 </body>
为什么select()调用不到,如果写成<a href="#" onclick="select()">查询</a> 则可以

[解决办法]
input本身有select方法,你可以换个名字测试下
另外,你 的id=select也容易出错 参考
http://blog.csdn.net/net_lover/article/details/7162136

function selectX(){}


var str = " ";
str += "日&nbsp期: ";
str += "<input type='text' id='time' name='time'/>";
str += "公司名称: ";
str += "<input type='text' name='gsmc'/>";
str += "<input type='button' onclick='selectX()' value='查询'>";
document.getElementById("login").innerHTML = str;

热点排行
Bad Request.