简体   繁体   English

使用 jQuery 从动态创建的项目中获取选定的列表值

[英]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.

相关问题 使用jQuery获取动态创建的多个下拉列表的选定值 - Get selected value of dynamically created multiple dropdown using jquery 如何使用 PHP 或 Jquery 从动态创建的下拉列表中获取所选选项的 ID? - how I can get the ID of the selected option from a dynamically created dropdown using PHP, or Jquery? 使用PHP获取动态创建的选定单选按钮值 - Get the dynamically created selected radio button value using PHP jQuery如何处理PHP动态创建的DropDown List的更改选定项事件 - How to handle the change selected item event of dynamically created DropDown List in PHP by jQuery jQuery使用.delegate()从.keypress()之后的动态创建内容中获取价值 - jQuery Get Value From Dynamically Created Content after .keypress() with .delegate() 使用jQuery在数据库中显示值到动态创建的文本字段 - Display the value from database to dynamically created textfield in the table using jQuery 识别从WordPress / PHP中动态创建的表单中选择了哪个项目 - Identifying which item was selected from a dynamically created form in WordPress / PHP 通过jQuery获取动态创建的输入的数组值 - get array value of dynamically created inputs by jquery 获取ID和值动态创建的元素jquery - get id and value dynamically created element jquery 如何使用php从下拉菜单中获取所选项目的值 - How to get value of selected item from dropdown menu using php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM