如何从 Javascript 中的自定义属性获取元素?
How to get Elements from a custom attribute in Javascript?
我想从下面的 HTML:
中提取带有 javaScript 的文本值
<div class="search-box-compact__label text-color-secondary">
<span data-bind="i18n: 'search.keyword-label'">Find Jobs</span>
</div>
我已经试过了,但没有用。请提出解决方案:
let y = document.querySelectorAll("[data-bind=`i18n: 'search.keyword-label'`]");
我收到以下错误::
Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document': '[data-bind=`i18n: 'search.keyword-label'`]' is not a valid selector.
请多多指教。
你需要转义'
,我用"
转
let y = document.querySelectorAll("[data-bind=\"i18n: \'search.keyword-label\'\"]");
console.log(y);
<div class="search-box-compact__label text-color-secondary">
<span data-bind="i18n: 'search.keyword-label'">Find Jobs</span>
</div>
我想从下面的 HTML:
中提取带有 javaScript 的文本值<div class="search-box-compact__label text-color-secondary">
<span data-bind="i18n: 'search.keyword-label'">Find Jobs</span>
</div>
我已经试过了,但没有用。请提出解决方案:
let y = document.querySelectorAll("[data-bind=`i18n: 'search.keyword-label'`]");
我收到以下错误::
Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document': '[data-bind=`i18n: 'search.keyword-label'`]' is not a valid selector.
请多多指教。
你需要转义'
,我用"
转
let y = document.querySelectorAll("[data-bind=\"i18n: \'search.keyword-label\'\"]");
console.log(y);
<div class="search-box-compact__label text-color-secondary">
<span data-bind="i18n: 'search.keyword-label'">Find Jobs</span>
</div>