点击加载/运行此代码
onclick load/run this code
我试图创建一个html文件,它将加载/运行以下代码单击按钮。我试过下面的方法。
<!-- Custom -->
<div id="custom1">
</div>
<script>
function custom()
{
var dummy = '<div id="custom1" style="display: block; position: absolute; top: 0px; left: 0px; z-index: 9999900; width: 100%; opacity: 0.8; height: 768px; visibility: visible;" ></div>
<div id="custom1" style="display: block; text-align: center; line-height: normal; visibility: visible; position: absolute; top: 0px; left: 0px; z-index: 9999910; width: 100%; height: 667px;" ><div id="close_button_div" align="center" style="position: absolute; width: 100%; z-index: 9999930;"></div><div style="background: transparent; height: 768px; z-index: 9999915;">
<iframe id="custom1" width="100%" height="768" id="overlay_iframe" src="" allowtransparency="true" frameborder="0" style="position: relative; height: 768px; overflow: hidden; z-index: 9999920; display: block; background-color: transparent;" scrollbars="NO" ></iframe>
</div>
</div>
<div id="custom1" align="center" style="position: absolute; width: 100%; z-index: 9999930;" ></div>
<div id="custom1" style="background: transparent; height: 768px; z-index: 9999915;" >
<iframe id="custom1" width="100%" height="768" id="overlay_iframe" src="captcha.php" allowtransparency="true" frameborder="0" style="position: relative; height: 768px; overflow: hidden; z-index: 9999920; display: block; background-color: transparent;" scrollbars="NO">
</iframe>
</div>
</div>';
document.getElementById('custom1').innerHTML += dummmy;
}
</script>
<!-- END custom-->
下面是我用于button onclick
的代码<a href="#" onclick="custom();">DOWNLOAD</a>
这对我不起作用。
删除 + innerHTML。
function custom()
{
var dummy = '<div id="custom1" style="display: block; position: absolute; top: 0px; left: 0px; z-index: 9999900; width: 100%; opacity: 0.8; height: 768px; visibility: visible;" ></div><div id="custom1" style="display: block; text-align: center; line-height: normal; visibility: visible; position: absolute; top: 0px; left: 0px; z-index: 9999910; width: 100%; height: 667px;" ><div id="close_button_div" align="center" style="position: absolute; width: 100%; z-index: 9999930;"></div><div style="background: transparent; height: 768px; z-index: 9999915;"><iframe id="custom1" width="100%" height="768" id="overlay_iframe" src="" allowtransparency="true" frameborder="0" style="position: relative; height: 768px; overflow: hidden; z-index: 9999920; display: block; background-color: transparent;" scrollbars="NO" ></iframe></div>
</div><div id="custom1" align="center" style="position: absolute; width: 100%; z-index: 9999930;" ></div><div id="custom1" style="background: transparent; height: 768px; z-index: 9999915;"><iframe id="custom1" width="100%" height="768" id="overlay_iframe" src="captcha.php" allowtransparency="true" frameborder="0" style="position: relative; height: 768px; overflow: hidden; z-index: 9999920; display: block; background-color: transparent;" scrollbars="NO"> </iframe></div></div>'; document.getElementById('custom1').innerHTML = dummmy;
}
演示:
http://jsfiddle.net/n70o70tz/您必须在dummy之前删除+符号。在你的代码中有 dummy 的变量名拼写错误。下面是工作代码
function custom()
{
var dummy= '<div id="custom1" style="display: block; position: absolute; top: 0px; left: 0px; z-index: 9999900; width: 100%; opacity: 0.8; height: 768px; visibility: visible;" ></div> <div id="custom1" style="display: block; text-align: center; line-height: normal; visibility: visible; position: absolute; top: 0px; left: 0px; z-index: 9999910; width: 100%; height: 667px;" ><div id="close_button_div" align="center" style="position: absolute; width: 100%; z-index: 9999930;"></div><div style="background: transparent; height: 768px; z-index: 9999915;"> <iframe id="custom1" width="100%" height="768" id="overlay_iframe" src="" allowtransparency="true" frameborder="0" style="position: relative; height: 768px; overflow: hidden; z-index: 9999920; display: block; background-color: transparent;" scrollbars="NO" ></iframe> </div> </div> <div id="custom1" align="center" style="position: absolute; width: 100%; z-index: 9999930;" ></div> <div id="custom1" style="background: transparent; height: 768px; z-index: 9999915;" ><iframe id="custom1" width="100%" height="768" id="overlay_iframe" src="captcha.php" allowtransparency="true" frameborder="0" style="position: relative; height: 768px; overflow: hidden; z-index: 9999920; display: block; background-color: transparent;" scrollbars="NO"> </iframe> </div> </div>';
document.getElementById('custom1').innerHTML = dummy;
}
<div id="custom1">
</div>
<a href="#" onclick="custom();">DOWNLOAD</a>
可能是语法错误这样做,尝试使用 +
操作符连接各个行。
<script>
function custom()
{
var dummy = '<div id="custom1" style="display: block; position: absolute; top: 0px; left: 0px; z-index: 9999900; width: 100%; opacity: 0.8; height: 768px; visibility: visible;" ></div>'+
'<div id="custom1" style="display: block; text-align: center; line-height: normal; visibility: visible; position: absolute; top: 0px; left: 0px; z-index: 9999910; width: 100%; height: 667px;" ><div'+ 'id="close_button_div" align="center" style="position: absolute; width: 100%; z-index: 9999930;"></div><div style="background: transparent; height: 768px; z-index: 9999915;">'+
'<iframe id="custom1" width="100%" height="768" id="overlay_iframe" src="" allowtransparency="true" frameborder="0" style="position: relative; height: 768px; overflow: hidden; z-index: 9999920; display: block; background-color: transparent;" scrollbars="NO" ></iframe>'+
'</div></div><div id="custom1" align="center" style="position: absolute; width: 100%; z-index: 9999930;" ></div>'+
'<div id="custom1" style="background: transparent; height: 768px; z-index: 9999915;" >'+
'<iframe id="custom1" width="100%" height="768" id="overlay_iframe" src="captcha.php" allowtransparency="true" frameborder="0" style="position: relative; height: 768px; overflow: hidden; z-index: 9999920; display: block; background-color: transparent;" scrollbars="NO">'+
'</iframe> </div> </div>';
document.getElementById('custom1').innerHTML += dummmy;
}
</script>
<!-- END custom-->
相关文章:
- 如果此代码运行,请执行代码
- JavaScript游戏引擎——编辑器中的代码运行:)检查器中的错误
- JavaScript中的逗号运算符:应为语法错误,但代码运行正常
- 代码运行时出现问题
- Socket.IO:重新连接导致服务器连接代码运行两次
- 代码运行时的类型检查
- 将页面控件添加到数据表,但当代码运行时,页面中不显示任何内容
- if 语句中的一部分 JavaScript 代码运行,而同一块中的其余代码不执行.我在这里错过了什么
- JS代码运行非常慢
- 阻止其他代码运行,直到 AJAX 请求返回某些内容
- JS代码运行到无限循环
- Javascript游戏代码运行非常慢
- chrome扩展///我的代码运行了不止一次
- 我的代码运行在jsfiddle上,但为什么不能't在本地计算机上
- Javascript parseInt-代码运行4次
- 如何从Visual Studio代码运行我的电子项目
- 检查显示:CANNON不是使用CANNON.js+Webstorm 8.0.1定义的(但代码运行良好)
- 为什么slice()显示错误,但代码运行良好
- 代码运行后字符串发生更改
- JQuery函数代码运行不正常