簡體   English   中英

嘗試根據JQuery屬性包含的內容更改h1標簽

[英]Trying to change an h1 tag based on the JQuery Attribute Contains

我在動態生成的頁面上有一個鏈接,該鏈接的href類似於<a href="/ListJobs/ByCustom/Job-Category/Keyword-Accounting-Finance/">Accounting/Finance</a><a href="/ListJobs/ByCustom/StationLocation/Keyword-KCCI-TV/">KCCI-TV</a> ,我需要根據鏈接的Job-Category或StationLocation部分更改h1標簽。 我嘗試使用

if ($("table a[href='/ListJobs'][href='/ByCustom'][href='/StationLocation']")) {
            alert($('table a').attr("href"));
        } else {
            alert("Category");
            $('#mainbody h1').html("Careers by Category");
        }

以及許多其他變體,包括

$("table a [href|='/ListJobs/ByCustom/Job-Category']

沒有任何努力取得預期的結果。 我應該使用什么來查看href是否包含所需的字符串部分,以便可以相應地更改h1標簽?

 $("table a").each(function() {
if (this.href.indexOf('StationLocation') != -1) {
   alert($('table a').attr("href"));
} else {
    alert("Category");
        $('#mainbody h1').html("Careers by Category");
    }
 });

如何使用^ ='開始於'運算符?

if ($("table a[href^='/ListJobs'][href^='/ByCustom'][href^='/StationLocation']")) {
    alert($('table a').attr("href"));
} else {
    alert("Category");
    $('#mainbody h1').html("Careers by Category");
}

http://api.jquery.com/attribute-starts-with-selector/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM