getElementById无法在javascript中运行 [英] getElementById not working in javascript

查看:57
本文介绍了getElementById无法在javascript中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在javascript中做一些练习示例。我想将输入框中的值分配给变量,然后通过警报打印它。但它不起作用。你可以帮忙纠正下面代码中的问题。谢谢。



Hello,
I am doing some practice example in javascript. I want to assign value from input box into variable and then print it via alert. However it is not working. could you please help to rectify the problem in below code. thanks.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  
</head>
 
<body>
  
  <label for="age1">Enter your age</label>
  <input type="text" name="age"> </input>
  <button type="submit" name="Enter" > Enter </button>

   </body>
 <script type="text/javascript" > 
 function verify()
     {
    
        var userage = parseInt(document.getElementById("age").value); 
        alert (userage) ;
      
   }
   
  </script>

  
</html>

推荐答案

你需要添加一个id =age 属性到您的输入标记。 name与id不一样
ou need to add an id="age" attribute to your input markup. "name" is not teh same as "id"


谢谢,它有效。感谢你的帮助。
thanks, it worked.appreciate your help.


这篇关于getElementById无法在javascript中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆