Js获取标签中的值

2017-08-11  本文已影响0人  lx_smile

在HTML中有如下代码,编写代码获取邮箱的值

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <form id = "myform" name = "myform" action = "">
     邮箱:<input type = "text" id = "email" name = "email"> 
     <button type = "submit" onclick = "test()">提交</button>
  </form>
</body> 
</html>
function test(){
  var form = document.getElementById("email").value;
  alert(form);
}
function test(){
  var form = document.forms["myform"]["email"].value;
  alert(form);
}
function test(){
  var form = document.myform.elements[0].value;
  alert(form);
}
function test(){
  var form = document.getElementsByName("email")[0].value;
  alert(form);
}
点击按钮之前 点击按钮之后
上一篇下一篇

猜你喜欢

热点阅读