无法从文本框中获取 jquery 中的值

Not able to get Value in jquery from textbox

本文关键字:获取 jquery 文本      更新时间:2023-09-26

我正在尝试从按钮单击事件的文本框中获取值,但收到错误,如下所示function (a){ return p.access(this.function(a).这是我用HTML编写的代码。

 <a href="#popupLogin" data-rel="popup" data-position-to="window" data-theme="b" data-transition="pop">Mobile</a>
 <div data-role="popup" id="popupLogin" data-theme="a" class="ui-corner-all">
 <form>
    <div style="padding:10px 20px;">
        <h3>Please Enter Mobile No.</h3>
        <label for="un" class="ui-hidden-accessible">Mobile No.:</label>
        <input type="text" name="user" id="un" value="" placeholder="Mobile" data-theme="a">
 <button type="submit" id="submitMobile" class="ui-btn ui-corner-all ui-shadow ui-btn-b ui-btn-icon-left ui-icon-check">Submit</button>
 </div>
</form>
</div>

这是jquery..

$(document).on('click', '#submitMobile', function() {
alert("Add Phone Number here");
CallingNo=$('#un').text;
alert(CallingNo);
});

请帮助我纠正此问题..谢谢。。

而不是文本使用 .val()

$(document).on('click', '#submitMobile', function() {
   alert("Add Phone Number here");
   CallingNo=$('#un').val();
   alert(CallingNo);
});

您需要使用 val() 获取inputvalue 属性:

$(document).on('click', '#submitMobile', function() {
    var callingNo = $('#un').val();
    alert(callingNo);
});