【发布时间】:2021-01-28 20:21:57
【问题描述】:
我正在尝试删除“|”从文件大小跨度标签。到目前为止,我的 javascript 代码的语法看起来不错,但它还不能正常工作。
据我了解,我使用了正确的 substr 语法:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr
在 Chrome 中,我收到此控制台错误:
未捕获的类型错误:无法读取未定义的属性“substr”
在 Firefox 中,我收到此控制台错误:
未捕获的类型错误:innerTextString 未定义。
还有“|”没有按预期删除。有什么想法我在这里出错了吗?
提前谢谢你。
<script>
const prettyLinkRightFileSize = document.querySelectorAll('.prettyFileList .float_right:nth-child(1)');
const innerTextString = prettyLinkRightFileSize.innerText;
innerTextString.substr(0);
</script>
.prettyFileList .float_right {
float: right;
}
<div class="prettyFileList">
<div>
<a href="#" class="prettylink">
<span class="float_right">| Size 150 KB</span>
<span class="float_right">28th Jan 2021</span>
</a>
</div>
</div>
【问题讨论】:
-
querySelector 不是 querySelectorAll
-
@danronmoon 我从 api 引用它 - developer.mozilla.org/en-US/docs/Web/API/Document/…
标签: javascript ecmascript-6 substring substr bem