2016-11-10 21 views
-4
<div id="divForm" class="fancybox" style="display:none;"> 
    <form id="frm_step1" action="download1.php" method="post"> 
     <label>Enter Email</label> 
     <input type="email" name="email" id="email" value="" required /> 
     <input type="button" name="submit" id="submit" value="Submit" class="form-submit" target-form="frm_step1" onclick="test();" /> 
    </form> 
</div> 
function test() { 
    var email = $('#email').text(); 
    alert(email); 
    $.ajax({ 
     type: "POST", 
     dataType: "json", 
     url: 'download1.php?email' + email, 
     data: { 'email': email }, 
     success: function(data) { 
      window.location.href = 'download.php#file'; 
     }, 
     error: function(e) { 
      alert('Error: ' + e); 
     } 
    }); 
} 

我无法从这个获取电子邮件。当我提醒它时,它将返回空白。 我一直使用这样的jQuery/AJAX,但这次它不会提示邮件地址。无法获取电子邮件地址的onclick功能

回答

2

使用.val()而不是.text().val()方法主要用于获取表单元素的值,如输入,选择textarea

$('#email').val(); 

function test() { 
 
    var email = $('#email').val(); 
 
    alert(email); 
 
    $.ajax({ 
 
     type: "POST", 
 
     dataType: "json", 
 
     url: 'download1.php?email' + email, 
 
     data: { 'email': email }, 
 
     success: function(data) { 
 
      window.location.href = 'download.php#file'; 
 
     }, 
 
     error: function(e) { 
 
      alert('Error: ' + e); 
 
     } 
 
    }); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id="divForm" class="fancybox"> 
 
    <form id="frm_step1" action="download1.php" method="post"> 
 
     <label>Enter Email</label> 
 
     <input type="email" name="email" id="email" value="" required /> 
 
     <input type="button" name="submit" id="submit" value="Submit" class="form-submit" target-form="frm_step1" onclick="test();" /> 
 
    </form> 
 
</div>

+0

我第一次使用VAL()而已,但仍然得到同样的错误。 – neha910

+0

我没有收到任何错误,但我也没有收到电子邮件,只是返回空白。 – neha910

+0

你做了什么,你运行相同的代码或你自己的代码。 – neha910

相关问题