amp-html - amp-script Uncaught TypeError:无法读取未定义的属性(读取“点击”)
问题描述
为什么这行不通?在我使用 Amp-script 的情况下,日志是成功的,但实际上并不能正常工作示例代码:
<amp-script script="btn-obs" layout="responsive" height="300" width="300" >
<input class="load-more" id="btnloadmore" type="submit" value="TEST BTN" on="tap:formme.submit" tabindex="0" role="button">
</amp-script>
<script id="btn-obs" type="text/plain" target="amp-script">
const loadmore = document.querySelector('#btnloadmore');
loadmore.addEventListener("click", () => {
console.log("cliked");
});
var left;
var right;
var bottom;
var top;
window.addEventListener("scroll", function(event){
let target = loadmore;
target.getBoundingClientRectAsync().then(coords => {
left = coords.left;
top = coords.top;
bottom = coords.bottom;
right = coords.right;
});
const isInViewport = top >= 0 &&
left >= 0 &&
bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
right <= (window.innerWidth || document.documentElement.clientWidth);
if(isInViewport == true){
loadmore.click();
console.log("yes")
}
});
</script>
我得到了如下错误:
[amp-script] Uncaught TypeError: Cannot read properties of undefined (reading 'click')
解决方案
推荐阅读
- r - 解释 gam.check() 生成的残差图中的模式
- ios - InApp 购买消耗品服务器验证设置
- flutter - 如何在颤动中修复mapbox上的白屏
- selenium - Selenium 在 chrome 中正常工作,但不适用于 chrome headless
- css - 如果字体大小设置为 1rem,行高(和元素高度)是多少?
- r - 删除 R 数据帧字符串变量中带有模式的后缀
- php - 如何使用带有 Symfony formbuilder 的 querybuilder 来连接两个实体?
- javascript - 在 ReactJS 中显示来自 Json 的多个图像
- python-3.x - Pandas 多列匹配,然后向后移动以查找值
- vue.js - 返回应用后状态栏返回,为什么?