[英]using jQuery get the selected list value from dynamically created item
im trying to get the value of selected item, my items are dynamically generated我正在尝试获取所选项目的值,我的项目是动态生成的
foreach ($result as $value){
?>
<a href="#" class="badge badge-info filteredcat" value="<?php echo $value['id'] ?>">
<?php echo $value['categorie'] ?>
</a>
<?php
}
?>
so after it loads the html looks like this所以加载后的html看起来像这样
<a href="#" class="badge badge-info filteredcat" value="5">
Semnalizare rutieră </a>
<a href="#" class="badge badge-info filteredcat" value="4">
Probleme de mediu </a>
<a href="#" class="badge badge-info filteredcat" value="6">
Spații verzi </a>
<a href="#" class="badge badge-info filteredcat" value="7">
Câini comunitari </a>
using jquery i want to get the value of selected item使用 jquery 我想获取所选项目的值
$('.filteredcat').click(function(){
let categorie = $(this).val();
//$.fn.startLoader();
console.log(categorie);
});
but i cant get the value ... if i use $(this).text() its working ... but not the value但我无法获得价值......如果我使用 $(this).text() 它的工作......但不是价值
You should be able to grab it with let categorieVal = $(this).attr("value");
您应该可以使用let categorieVal = $(this).attr("value");
来获取它let categorieVal = $(this).attr("value");
since it is one of the elements' attributes.因为它是元素的属性之一。 See .attr() |见.attr() | jQuery API Documentation jQuery API 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.