Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取下拉引导onclick Jquery函数的值_Javascript_Jquery_Bootstrap 4 - Fatal编程技术网

Javascript 获取下拉引导onclick Jquery函数的值

Javascript 获取下拉引导onclick Jquery函数的值,javascript,jquery,bootstrap-4,Javascript,Jquery,Bootstrap 4,我的HTML文件中有一个表,在其中一列中有一个来自bootstrap的按钮组件,单击按钮时,会出现一个下拉列表,其中有三个选项—“中”、“低”、“servicerequest”。单击此项目时,我正在尝试获取所单击项目的值 $(“.table table hover table condensed”)。在('单击','上。下拉菜单',函数(e){ var id=$(this.attr(“#mediumpriority”); 警报(id); }); @import-url('//netdna.bo

我的HTML文件中有一个表,在其中一列中有一个来自bootstrap的按钮组件,单击按钮时,会出现一个下拉列表,其中有三个选项—“中”、“低”、“servicerequest”。单击此项目时,我正在尝试获取所单击项目的值

$(“.table table hover table condensed”)。在('单击','上。下拉菜单',函数(e){
var id=$(this.attr(“#mediumpriority”);
警报(id);
});
@import-url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
身体{
利润率:10px;
}

优先
高
中等
低
服务请求

到jQuery选择器的命令看起来不正确。应该是

$(".table.table-hover.table-condensed").on('click', '.dropdown-item', function(e) { 
    var menu = $(this).html();
    alert(menu);
});

此选择器错误:

$(".table table-hover table-condensed")
          ^           ^
使用以下命令:
.table.table hover.table condensed

要获取属性id,请使用以下命令:
$(this.attr('id')

事件委派调用使用了错误的子级选择器

$(".table table-hover table-condensed").on('click', '.dropdown-menu', function(e) {
                                                     ^
改为使用此选项:
。下拉项

$(“.table.table hover.table condensed”)。在('click','下拉项',函数(e){
var text=$(this.text();
警报(文本);
});
@import-url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
身体{
利润率:10px;
}

优先
高
中等
低
服务请求

#mediumpriority
不是一个属性。这不起作用:我得到了“未定义”我刚刚更新了我的答案。这接近我想要的,但id输出了“mediumpriority”,而我在“Medium”之后。下面已经回答了。@RA19嗯,你想要HTML吗。我建议使用.text()以避免HTML标记出现问题。答案更新!