Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery更改多个动态PHP生成的文本框的值_Php_Javascript_Jquery_Dynamically Generated Co - Fatal编程技术网

使用jquery更改多个动态PHP生成的文本框的值

使用jquery更改多个动态PHP生成的文本框的值,php,javascript,jquery,dynamically-generated-co,Php,Javascript,Jquery,Dynamically Generated Co,我使用PHP和name=“student[]”生成了多个文本框 现在单击一个按钮,我想使用jquery更改所有这些文本框的值 我该怎么做?请提供帮助。您可以使用,在名称属性的开头查找学生[: $('input[name^="student["]').val('the new value'); 可能没有必要在末尾包含[,假设您没有其他名为student\u name之类的输入,那么name^=“student”就足够了 // If no conflicting named inputs, use

我使用PHP和
name=“student[]”
生成了多个文本框

现在单击一个按钮,我想使用jquery更改所有这些文本框的值

我该怎么做?请提供帮助。

您可以使用,在名称属性的开头查找
学生[

$('input[name^="student["]').val('the new value');
可能没有必要在末尾包含
[
,假设您没有其他名为
student\u name
之类的输入,那么
name^=“student”
就足够了

// If no conflicting named inputs, use
$('input[name^="student"]').val('the new value');
您可以使用,在name属性的开头查找
student[

$('input[name^="student["]').val('the new value');
可能没有必要在末尾包含
[
,假设您没有其他名为
student\u name
之类的输入,那么
name^=“student”
就足够了

// If no conflicting named inputs, use
$('input[name^="student"]').val('the new value');
HTML

<input type="text" name="student[]"></input>
<input type="text" name="student[]"></input>
<input type="text" name="student[]"></input>

<button id="button">Change</button>
HTML

<input type="text" name="student[]"></input>
<input type="text" name="student[]"></input>
<input type="text" name="student[]"></input>

<button id="button">Change</button>

您也可以简单地添加一个对所有这些文本框(即changableTextBox)都是唯一的类,然后用该类选择它,然后一次更改所有文本框。如果您需要同时调整所有文本框的某些样式,这对将来也很有帮助。只需在CSS中声明该类,您就可以进行样式设置

<input type="text" class="changeableStudentTextBox" id="student[11]" />
<input type="text" class="changeableStudentTextBox" id="student[23]" />
<input type="text" class="changeableStudentTextBox" id="student[45]" />
<input type="text" class="changeableStudentTextBox" id="student[66]" />

<script type="text/javascript">
     $('#button').click( function() { $('.changeableStudentTextBox').val('hi!'); });
</script>

$('#按钮')。单击(函数(){$('.changeableStudentTextBox').val('hi!');});

您也可以简单地添加一个对所有这些文本框(即changableTextBox)都是唯一的类,然后用该类选择它,然后一次将它们全部更改。如果您需要一次调整所有文本框的某些样式,这对将来也很有帮助。只需在CSS中声明该类,您就可以进行样式设置

<input type="text" class="changeableStudentTextBox" id="student[11]" />
<input type="text" class="changeableStudentTextBox" id="student[23]" />
<input type="text" class="changeableStudentTextBox" id="student[45]" />
<input type="text" class="changeableStudentTextBox" id="student[66]" />

<script type="text/javascript">
     $('#button').click( function() { $('.changeableStudentTextBox').val('hi!'); });
</script>

$('#按钮')。单击(函数(){$('.changeableStudentTextBox').val('hi!');});

名称包括
[]
name=“student[]
@Michael是的,我在发布答案后看到问题发生了变化,现在更新了。名称包括
[]
name=“student[]中的PHP提供的id
@Michael是的,在我发布了答案后,我看到问题发生了变化,现在更新了。你最好在你的周围添加
selectors@Michael:但是,先生,如果我有一些其他元素也以“student…”开头,那么我该怎么办?我是否必须使用foreach循环来循环所有学生ID,然后执行以下操作:------------:$('input[name=“student[]”).val('new value');@sqlchild那么我的第一个示例应该可以使用部分选择器
student[
您可能最好在您的周围添加
selectors@Michael:但是,先生,如果我有一些其他元素也以名称“student…”开头,那么我该怎么办?我是否必须使用foreach循环来循环所有学生ID,然后执行以下操作:-----------:$('input[name=“student[]”.val('new value'));@sqlchild那么我的第一个示例应该可以使用部分选择器
student[