程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用 jquery 从 html 获取 aria-label大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决使用 jquery 从 html 获取 aria-label?

开发过程中遇到使用 jquery 从 html 获取 aria-label的问题如何解决?下面主要结合日常开发的经验,给出你关于使用 jquery 从 html 获取 aria-label的解决方法建议,希望对你解决使用 jquery 从 html 获取 aria-label有所启发或帮助;

有没有什么办法可以使用 jquery 获取 aria-label 的值?@H_419_1@

我有这个功能@H_419_1@

$(document).ready(function() {
    console.log("dom ready")
    $(document).on('click','.clicker',function(E) {
        e.preventDefault();
        e.stopPropagation();
        var hrefValue = this.href;
        var label = this.aria - label;
        var ID = this.ID;
        console.log("aria label " + label);
        fire(hrefvalue)
    });
});

如果我想从这个下拉列表中获取 hrefValue,这会起作用:@H_419_1@

<a class="dropdown-toggle rootelements clicker" role="button" aria-label="'+elem.appname+'" data-toggle="dropdown" data-toggle="tooltip" title=' + elem.link + ' href="' + elem.value +'"><i style="color:' + elem.iconcolor + ';" class="' + elem.icon + '" ID="Jsonicon"></i></a>

但是这个console.log("aria label " +label) 当预期输出为 aria label NaN@H_419_1@ 时为我返回 deBUG

解决方法

https://api.jquery.com/attr/

# file2.txt got removed,because it does not represent 
# path to an exisTing file
"file1.txt folder/file3.txt"
,

您可以使用驼峰式大小写或 bracket notation,因为 aria-label 包含连字符,这使其不是有效标识符,因此不能在 dot notation 中使用。

var label = this.ariaLabel;
// or
var label = this['aria-label'];

大佬总结

以上是大佬教程为你收集整理的使用 jquery 从 html 获取 aria-label全部内容,希望文章能够帮你解决使用 jquery 从 html 获取 aria-label所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。