2013-07-29 61 views
1

我想使用js获取输入的值,但它不起作用。我的错误在哪里? 警报不起作用。使用javascript获取输入值

<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> 

js文件:

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

}

回答

1

您的邮箱输入不具有ID:

<input type="text" name="email" id="email" /> 
0

电子邮件一个名字,只是改变 '的名字' 到 '身份证' ^^

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> 
0

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

<input type="text" name="email" id="email" ></input> 
0

你忘了提id='email'input元素。