开发者

how to retrieve the value from text field?

How to retrieve the value from text field? And h开发者_如何学运维ow to concanate the value in jquery?


var value = $('#textFieldId').val(); // jQuery
var otherValue = value + ' is now concatenated'; // basic JavaScript

Reference: val(), Introduction to strings in JavaScript


To get a value of an input give it an id and use the following

var inp = $('#idofinputfield').val();

and to concatenate use the + sign

var inp1 = 'test';
var inp_concat = inp1 + ' ' + inp;


Getting the value:

var value = $('input#id').val();

Setting the value:

var value = $('input#id').val('newvalue');

Adding to the value:

var $input = $('input#id');
$input.val( $input.val() + ' something else' );

Note that the selector I've used specifies both the tag and the id. Of course, you could simply use the id since it is unique (as long as your HTML is valid). Adding the tag can help with readability if the id isn't semantically rich, which is why I've used it in the example. If your input's id is descriptive, there's probably no need for it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜