为了账号安全,请及时绑定邮箱和手机立即绑定

请问这样为什么不出

<script type="text/javascript">

 function clock(){

    var time=new Date();

    document.getElementById("clock").value = time;

  }

</script>

</head>

<body>

  <form>

    <input type="text" id="clock" size="50"  />

  </form>


正在回答

3 回答

function clock()没有起作用,需要在文本框内执行运算,如 onfocus="clock()"

0 回复 有任何疑惑可以回复我~
#1

木a 提问者

非常感谢!
2016-12-01 回复 有任何疑惑可以回复我~

你js里面的方法没有被调用,你是想在id为time的文本框里显示时间,那么id为time的文本框需要通过事件调用js里面的方法。

0 回复 有任何疑惑可以回复我~

<!DOCTYPE html>

<html>

   <head>

<script type="text/javascript">

function clock(){

var time = new Date();

document.getElementById('time').value = time;

}

</script>

</head>

  <body>

 <form>

<input type="text" id="time" onfocus="clock()"  size="50"  />

 </form> 

  </body>

</html>


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

请问这样为什么不出

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信