[英]How to get looped input value specifically using Jquery
del_id = $('.button').attr('rel');
alert(del_id)
PHP: PHP:
while ($row=mysqli_fetch_assoc($rs)) {
?>
<div class="itemsin" >
<span data-toggle="confirmation" rel="<?php echo $row['id']?>" class="button" id="rmlb">Click to Remove </span>
</div>
<?php
}
}
?>
I tried this but it's alerting only the first value out printed by loop please give me a suggestion 我尝试了这个,但它只警告循环打印出的第一个值,请给我一个建议
First of all, please post corrected and formatted code in future. 首先,请以后发布经过更正和格式化的代码。
Here is what you need: 这是您需要的:
Collected all PHP output data in an JS array or object 将所有PHP输出数据收集到JS数组或对象中
Create a loop in JS to print all array values. 在JS中创建一个循环以打印所有数组值。
You need to be carefull with alerting each value because it will give a you a popup box for each array item and the annoying popup will never finish. 您需要警惕每个值,因为它将为您提供每个数组项的弹出框,而烦人的弹出框将永远不会结束。 I suggest outpoint them in console to see the result.
我建议在控制台中将它们外包,以查看结果。
Your JS Code: 您的JS代码:
del_id = document.querySelectorAll (".button");
for(var i = 0; i < del_id.length; i++){
attrValue = $(this).attr('rel');
console.log(attrValue);
//You can also alert it if you wish to:
//alert(attrValue);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.