-1

我想知道这个问题的答案。这是一个例子:

代码:

<input type='text' name='input_name' id='input_id' value='something'>
4

4 回答 4

1

您可以使用.val()

$("input[type='text']").val() // CSS 3 kind a selectors:: used to loop through all the textboxes and perform operation

 **Or**

$("#input_id").val()

如果您在输入中添加了类,则可以使用

$(".inputClass").val()

ID 可以是多个且唯一的,注意 ID 是最快的选择器,类比 ID 慢

您可能会看到选择器

于 2013-10-07T11:12:02.290 回答
0

最好的方法是使用jQuery 的内置.val()函数

$( "#input_id" ).val();

.attr()您还可以使用以下函数提取该属性:

$( "#input_id" ).attr( "value" );
于 2013-10-07T11:12:24.717 回答
0

您应该使用 jQuery val() 方法从输入中获取值。请参阅 jQuery API 文档:

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

于 2013-10-07T11:12:24.813 回答
0

尝试这样的事情

ID 是唯一的,因此与其他方法相比,它会更快地检索它。

    $(function(){
        $('#input_id').val();
    })
于 2013-10-07T11:12:31.943 回答