2

我正在尝试使用 js 获取输入值,但它不起作用。我的错误在哪里?

警报不起作用。

<body>
   <form name="inputform" id="form1" action="html_form_action.asp" method="get" style="visibility:hidden">
      Email: <input type="text" name="email" ></input>
      <input type="button" value="Gönder" onclick="CreateU()"></input>
   </form>
</body>

.js 文件:

var xmail="";
CreateU = function(){
  var xx = "";
  xmail=document.getElementById('email').value;
  alert(xmail);
  xx= myAddress + xmail + ans + tf;
  window.location.assign(xx);
}
4

6 回答 6

2

您的电子邮件输入没有 ID:

<input type="text" name="email" id="email" />
于 2013-07-29T06:56:43.840 回答
1

添加id到您的“电子邮件”输入:<input type="text" name="email" id="email" ></input>

看看: http: //jsfiddle.net/K8kp9/

请注意,现在您可能什么也看不到,因为style="visibility:hidden"您的form标签。

阅读:HTML 中 id 和 name 属性之间的区别

于 2013-07-29T06:56:57.340 回答
0

id='email'你忘了在你的input元素中提及。

于 2013-07-29T07:15:02.890 回答
0

在输入中使用 id 属性通过 document.getElementById() 获取值。

<input type="text" name="email" id="email" ></input>
于 2013-07-29T06:58:57.907 回答
0

电子邮件是一个名字,只需将'name'更改为'id' ^^

于 2013-07-29T06:57:55.010 回答
0

请在电子邮件中设置id

 <body>
    <form name="inputform" id="form1"  action="html_form_action.asp" method="get"       style="visibility:hidden">
    Email: <input type="text" name="email" id="email" ></input>
    <input type="button" value="Gönder" onclick="CreateU()"></input>
于 2013-07-29T06:58:07.680 回答