[英]using jquery to find value of hidden form value
I hope someone has he answer to my problem... 我希望有人能回答我的问题...
I'm trying to use jquery to find the value of different hidden fields on a form. 我正在尝试使用jquery查找表单上不同隐藏字段的值。 My problem is I have multiple forms appearing on the same page (items of a result set for updating) and the jquery only finds the value of the first field.
我的问题是我在同一页面上出现了多种形式(用于更新的结果集的项目),而jQuery只找到第一个字段的值。 When I click on the div to update the field I only get the ID of the first record.
当我单击div来更新字段时,我仅获得第一条记录的ID。
Here is my code 这是我的代码
repeated html 重复的HTML
<ul class="task-container-item">
<form id="task-submit" method="post" name="form">
<input class="taskID" type="hidden" value="<?php echo $taskID;?>">
<li><?php echo $name;?></li>
<li><?php echo $date;?></li>
<li><?php echo $creator;?></li>
<li class="description"><?php echo $description;?></li>
</form>
</ul>
jquery jQuery的
$(document).ready(function(){
$('.task-container-item').click(function(){
$(this).css("background","green")
$(this).css("color","#fff");
var taskID = $(".taskID").val();
alert (taskID);
});
});
Hope you can help 希望你能帮忙
Thanks 谢谢
Dave 戴夫
Perhaps you could have php increment the forms' inputs' id. 也许您可以让php递增表单的输入ID。
For instance: 例如:
<input class="taskID" type="hidden" id="taskid-1" value="<?php echo $taskID;?>">
and then for the next input 然后输入下一个
<input class="taskID" type="hidden" id="taskid-2" value="<?php echo $taskID;?>">
for(var x=0;x<?php echo $total_forms; ?>;x++){
//your processing code here
}
Try: 尝试:
$('input[type=hidden]')
Then you could use .each()
for each hidden field. 然后,您可以对每个隐藏字段使用
.each()
。
You can iterate on the list of elements with given class: 您可以使用给定的类在元素列表上进行迭代:
var taskIDs = [];
$('.taskID').each(function() {
taskIDs.push($(this).val());
});
You'll have all the ids in the taskIDs
array 您将在
taskIDs
数组中拥有所有ID
update 更新
$(document).ready(function(){
$('.task-container-item').click(function(){
$(this).css("background","green")
$(this).css("color","#fff");
var taskID = $(this) // Use the element that has been clicked on
.find(".taskID") // find the .taskID element in that
.val();
alert(taskID);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.