简体   繁体   English

用jQuery分配输入文本字段的初始值

[英]assigning initial value of input text field with jquery

I am trying to assign an initial value to a text box with using jquery. 我正在尝试使用jquery将初始值分配给文本框。 This is the text field 这是文本字段

  <input type="text" class="info"/>

This creates more than one text fields and I need to populate the text fields with initial values which come from database. 这将创建多个文本字段,而我需要使用来自数据库的初始值填充文本字段。 I am having problem since I am trying to it with jquery adapter. 我有问题,因为我正在尝试使用jquery适配器。

Any clue on this? 有什么线索吗?

Thanks in advance. 提前致谢。

Here is the detailed code: 这是详细的代码:

I include index.html 我包含index.html

       <?php include "index.html"?>;  

which puts some text fields to record.php: ... ... 它将一些文本字段记录到record.php:... ...

After including index.html I am using this code to assign intial value to the text boxes which have a class name "info": 包含index.html之后,我将使用以下代码为具有类名“ info”的文本框分配初始值:

         $('.info').each(function() {
                $('.info').val('yourvalue');
            });

Instead of assigning a constant value (here it is "yourvalue") I am going to assing some database records to each input fields. 而不是分配一个常量值(这里是“ yourvalue”),而是将一些数据库记录分配给每个输入字段。

$('.info').val('yourvalue');

replace yourvalue with the value you want to set.. 将您的值替换为您要设置的值。

Set this value in the success callback of your ajax request.. 在ajax请求的成功回调中设置此值。

$('.info').val('value-to-be-set');

.val( value ) - Set the value of each element in the set of matched elements .val(value)-设置匹配元素集中每个元素的值

Above code will set the value of the input fields where the class name if 'info' 上面的代码将设置输入字段的值,如果“ info”为类名

Read More here 在这里阅读更多

 $('.aciklama').each(function() { $('.aciklama').val('yourvalue'); }); 

you know $('.aciklama') is an array , and when you iterator you array get the object, you still get the $('.aciklama') array and set the array value, as I see It is not correct. 您知道$('。aciklama')是一个数组,并且当您迭代器使用数组获取对象时,您仍然会获得$('。aciklama')数组并设置数组值,如我所见,这是不正确的。 You should write like this: 您应该这样写:

$('.aciklama').each(function(index, item) { $(item).val('yourvalue'); }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM