找到包含 window.location.href 的标签
find a tag that contains the window.location.href
为了替换我页面上显示语言的文本,
我想找到包含 window.location.href url 的 'a' 标签并将其文本设置为当前语言文本
我试过:a[href=window.location.href]
但它不起作用
var href = window.location.href;
var currentLangVal = jQuery('.countrySelector a[href=href ]').text();
jQuery('.language-display').text(currentLangVal);
您需要的是字符串连接,在这种情况下,您需要 href
变量的 value,而不是 "href"
本身。
var href = window.location.href;
var currentLangVal = jQuery('.countrySelector a[href="' + href + '"]').text();
jQuery('.language-display').text(currentLangVal);
为了替换我页面上显示语言的文本, 我想找到包含 window.location.href url 的 'a' 标签并将其文本设置为当前语言文本
我试过:a[href=window.location.href] 但它不起作用
var href = window.location.href;
var currentLangVal = jQuery('.countrySelector a[href=href ]').text();
jQuery('.language-display').text(currentLangVal);
您需要的是字符串连接,在这种情况下,您需要 href
变量的 value,而不是 "href"
本身。
var href = window.location.href;
var currentLangVal = jQuery('.countrySelector a[href="' + href + '"]').text();
jQuery('.language-display').text(currentLangVal);