Javascript 如何在循环生成元素时使用jquery从PHPs中选择特定元素?
首先,我是网络编程新手。也就是说,如果您能以最容易理解的方式向初学者展示,我将不胜感激。 我正在尝试使用jQuery从while循环生成的列表中选择和编辑。我想要的是在用户单击编辑链接并输入另一个可用成员时更新可用成员。 我的代码如下: PHPJavascript 如何在循环生成元素时使用jquery从PHPs中选择特定元素?,javascript,php,jquery,Javascript,Php,Jquery,首先,我是网络编程新手。也就是说,如果您能以最容易理解的方式向初学者展示,我将不胜感激。 我正在尝试使用jQuery从while循环生成的列表中选择和编辑。我想要的是在用户单击编辑链接并输入另一个可用成员时更新可用成员。 我的代码如下: PHP 但这只会更新名字。即使单击最后一个成员名称,它也只对第一个成员名称应用更改。您可以执行以下操作: $(".edit").click(function () { //display hidden form $(this).find('for
但这只会更新名字。即使单击最后一个成员名称,它也只对第一个成员名称应用更改。您可以执行以下操作:
$(".edit").click(function () {
//display hidden form
$(this).find('form').show();
//when the previously hidden button is clicked, grab the value in the input field & send to update.php
$(this).find('button').click(function () {
var input = []; // create a new empty array
$('#hidden_form').each($('input'), function(){ // loop over each of the inputs
input.push($(this).val()); // grab input value and add it to the array
});
$.post("internal/update.php",{input:input},function(data) {
alert("Updated");
});
});
});
还没有测试过,所以可能会有一些问题
$(".edit").click(function () {
//display hidden form
$(this).find('form').show();
//when the previously hidden button is clicked, grab the value in the input field & send to update.php
$(this).find('button').click(function () {
var staffs = $("input=[class='staff_name']").val();
$.post("internal/update.php",{staffs:staffs},function(data) {
alert("Updated");
});
});
});
$(".edit").click(function () {
//display hidden form
$(this).find('form').show();
//when the previously hidden button is clicked, grab the value in the input field & send to update.php
$(this).find('button').click(function () {
var input = []; // create a new empty array
$('#hidden_form').each($('input'), function(){ // loop over each of the inputs
input.push($(this).val()); // grab input value and add it to the array
});
$.post("internal/update.php",{input:input},function(data) {
alert("Updated");
});
});
});