简体   繁体   English

此Javascript代码有什么问题?

[英]What's wrong with this Javascript code?

<a href="javascript:document.getElementById('create_table').style.display='block'">Insert Table</a>

该代码在Google Chrome浏览器中工作正常,但在Internet Explorer和Firefox中仅将其重定向到带有文本“阻止”的页面

Your qoutes are wrong: 您的qoutes错误:

javascript:document.getElementById('create_table').style.display=''block

It must be: 一定是:

javascript:document.getElementById('create_table').style.display='block'

But you shouldn't use javascript: pseudo-protocol anyway. 但是无论如何,您都不应该使用javascript:伪协议。 Better use JavaScript to only enrich your document . 更好地使用JavaScript来丰富文档

You should never use the javascript: pseudoprotocol. 永远不要使用javascript:伪协议。 Use the click event for this. 为此, click使用click事件。 Besides, also watch the quotes. 此外,还请注意报价。

Here's the correct approach: 这是正确的方法:

<a href="#" onclick="document.getElementById('create_table').style.display='block'; return false;">Insert Table</a>

Note that I (optionally) returned false here to block the default action. 请注意,我(可选)在此处返回false以阻止默认操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM