Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day390:下面的代码有什么问题?怎么优化? #393

Open
qappleh opened this issue Sep 3, 2021 · 1 comment
Open

Day390:下面的代码有什么问题?怎么优化? #393

qappleh opened this issue Sep 3, 2021 · 1 comment
Labels

Comments

@qappleh
Copy link
Owner

qappleh commented Sep 3, 2021

// what's wrong here?
let noscript = document.getElementById('noscript');
noscript.innerHTML = '<p>Please enable JavaScript.</p>';
document.body.appendChild(noscript);

注:本题转自推特一国外的小哥。

@qappleh qappleh added the js label Sep 3, 2021
@qappleh
Copy link
Owner Author

qappleh commented Sep 6, 2021

1、使用DOM没有判空;
2、id和变量名不应该使用html标签,命名不规范;
3、不能对为空或null的dom使用innerHTML属性;
4、appendChild()方法的参数不能是空或null;

可以在浏览器运行一下,看一下报错!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant