问题描述
我尝试了这个:
在constant.js
const CONFIRM_BUTTON = document.querySelector(".confirm-button");
export { CONFIRM_BUTTON };
在some-file.js中,
import { CONFIRM_BUTTON } from './constants';
CONFIRM_BUTTON.onclick = someFunction;
我正在这样做Cannot set property 'onclick' of null
获取Cannot set property 'onclick' of null
错误的Cannot set property 'onclick' of null
。
如果在some-file.js文件中,则执行以下操作:
const CONFIRM_BUTTON = document.querySelector(".confirm-button");
CONFIRM_BUTTON.onclick = someFunction;
我正在尝试这样做const CONFIRM_BUTTON = document.querySelector(".confirm-button");
一次并使用多个js文件?
我怎样才能做到这一点?
1楼
Max
1
2019-03-02 20:56:37
您只需要export CONFIRM_BUTTON
而无需弯曲的括号