import testBtn from '/functions.js'
window.onload = function() {
document.getElementById('questions1').style.display = 'block'
document.getElementById('questions2').style.display = 'none'
document.getElementById('questions3').style.display = 'none'
document.getElementById('questions4').style.display = 'none'
document.getElementById('questions5').style.display = 'none'
}
function nextQuestion() {
testBtn("hello")
}
当我尝试导入或将脚本类型更改为时,所有功能都不起作用type="module"
当脚本类型没有导入或更改时,该函数起作用,并且我收到以下错误 -Uncaught ReferenceError: nextQuestion is not defined at HTMLButtonElement.onclick
ECMAScript 模块不使用全局作用域,因此onclick="nextQuestion"
HTML 元素上的属性将无法找到nextQuestion
因为它不在全局范围内,而是在模块范围内(与type="module"
)。要解决此问题,请将nextQuestion
函数进入全局范围:
window.nextQuestion = function() {
testBtn("hello")
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)