jQuery: If this HREF contains

前端 未结 6 1855
南笙
南笙 2021-01-30 20:51

Why can\'t I get this to work??

$(\"a\").each(function() {
    if ($(this[href$=\"?\"]).length()) {
        alert(\"Contains questionmark\");
    }
});
         


        
6条回答
  •  广开言路
    2021-01-30 21:22

    use this

    $("a").each(function () {
        var href=$(this).prop('href');
        if (href.indexOf('?') > -1) {
            alert("Contains questionmark");
        }
    });
    

提交回复
热议问题