开发者

jQueryMobile can't get value of input textbox on iPhone

开发者 https://www.devze.com 2023-03-15 13:39 出处:网络
I have a simple jQM form with some inputs, the problem is I can\'t retrieve the value of an input through JS when testing on the iPhone, main desktop browsers are working.

I have a simple jQM form with some inputs, the problem is I can't retrieve the value of an input through JS when testing on the iPhone, main desktop browsers are working.

Here's part of the form:

<div data-role="fieldcontain">
   <input type="text" name="fname" id="fname" />


   <input type="text" name="lname" id="lname" />

   <input type="button" value="Go" onclick="validate()" />
</div>

The Javascript:

function validate()
{
    alert('value: ' + $('#fname').val());
}

The alert shows literally as:

value:

Also tried using the traditional .value method.

Version in use:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script type=开发者_如何学JAVA"text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>

Edit: added more code for clarification.


Make sure you are in the document ready:

$(function(){
     alert($('#fname').val()); //should be nothing bc the input has no value yet
});
0

精彩评论

暂无评论...
验证码 换一张
取 消