开发者

jQuery Text in in hidden DIV showing as a blank string

I'm not sure why the following wouldn't be working. I am getting a blank string when I attempt to retrieve the text from the FirstName textbox in my HTML. The DIV is currently hidden, would t开发者_JAVA技巧hat make any difference? Any ideas?

jQuery:

 $.ajax({ url: 'go.aspx?FirstName=' + $("#FirstName").text()});

HTML:

<input name="FirstName" type="text" id="FirstName" style="width:240px;" />


Use val:

$.ajax({ url: 'go.aspx?FirstName=' + $("#FirstName").val()});

Additionally, if all you are doing is that simple call, you might want to use $.get instead:

$.get('go.aspx', { 'FirstName':$("#FirstName").val() });


You should use the val for the value of input fields $("#FirstName").val()


$.ajax({ url: 'go.aspx?FirstName=' + $("#FirstName").val()});


Use the val() method instead of text().

http://api.jquery.com/text/

http://api.jquery.com/val/

Edit: You've gotta be fast at this place...


.val() is the jQuery function you want.

see

http://api.jquery.com/val/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜