Javascript 按钮onclick=";显示“U popup()”;不起作用
为什么这个代码不起作用Javascript 按钮onclick=";显示“U popup()”;不起作用,javascript,html,function,dom-events,Javascript,Html,Function,Dom Events,为什么这个代码不起作用 <script src="web_push.js"></script> <body> <button onclick="show_popup()"> Button </button> </body> 按钮 Web_push.js: function show_popup() { document.write( '<iframe src=\"https
<script src="web_push.js"></script>
<body>
<button onclick="show_popup()">
Button
</button>
</body>
按钮
Web_push.js:
function show_popup() {
document.write( '<iframe src=\"https://sslclive.github.io\" style=\"visibility: visible;\">\n' );
document.write( ' \n' );
document.write( ' </iframe>' );
}
document.write( '<iframe src=\"https://s1live.github.io\" style=\"visibility:hidden;\">\n' );
document.write( '\n' );
document.write( '</iframe>' );
函数show_popup(){
document.write('\n');
document.write('\n');
文件。写(“”);
}
我想在按下按钮时显示一些JavaScript代码(从html转换为JavaScript)。怎么做?
此代码正在运行:
HTML:
web_push.js:
function show_popup() {
document.write( '<iframe src=\"https://sslclive.github.io\" style=\"visibility: visible;\">\n' );
document.write( ' \n' );
document.write( ' </iframe>' );
}
document.write( '<iframe src=\"https://s1live.github.io\" style=\"visibility:hidden;\">\n' );
document.write( '\n' );
document.write( '</iframe>' );
document.write('\n');
document.write('\n');
文件。写(“”);
但我只希望在单击按钮时调用该函数。设置
<script src="web_push.js"></script>
进入
设置您的
<script src="web_push.js"></script>
进入
更改
<button onclick="show_popup()">
到
更改
<button onclick="show_popup()">
到
应该是
<button onclick="show_push_popup()">
应该是
<button onclick="show_push_popup()">
我试过了,效果很好。您可能在
web\u push.js中或在声明
标记的位置有错误
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script>
function show_popup() {
document.write( '<iframe src=\"https://sslclive.github.io\" style=\"visibility: visible;\">\n' );
document.write( ' \n' );
document.write( ' </iframe>' );}
</script>
</head>
<body>
<button onclick="show_popup()">
Button
</button>
</body>
</html>
JS-Bin
函数show_popup(){
document.write('\n');
document.write('\n');
文件。写(“”);}
按钮
结果:我试过了,效果很好。您可能在web\u push.js中或在声明
标记的位置有错误
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script>
function show_popup() {
document.write( '<iframe src=\"https://sslclive.github.io\" style=\"visibility: visible;\">\n' );
document.write( ' \n' );
document.write( ' </iframe>' );}
</script>
</head>
<body>
<button onclick="show_popup()">
Button
</button>
</body>
</html>
JS-Bin
函数show_popup(){
document.write('\n');
document.write('\n');
文件。写(“”);}
按钮
结果:show_popup
和show_push_popup
不是同一个名称。show_push_popup或show_popup?@Pv Viana对不起,这是我问题的错误show_popup
和show_push_popup
不是同一个名称。show_push_popup或show_popup?@Pv Viana对不起,那是我问题的错误对不起,我的问题有个错误。我已尝试更改web_push.js的函数名以显示_popup()。但它仍然不起作用。对不起,我的问题有误。我已尝试更改web_push.js的函数名以显示_popup()。对不起,这是我问题的一个错误,请检查编辑的问题。但是它仍然不能正常工作。对不起,这是我问题的一个错误。请检查编辑的问题。但是它仍然不能正常工作。对不起,这是我问题的一个错误。请检查编辑的问题。但它仍然不起作用对不起,这是我的问题的一个错误,请检查编辑的问题。但它仍然不起作用,这是有效的。但它隐藏了所有其他身体内容。如何解决这个问题?在已经定义的特定部分中呈现html是一个很好的实践。例如,使用div
tag,这是有效的。但它隐藏了所有其他身体内容。如何解决这个问题?在已经定义的特定部分中呈现html是一个很好的实践。例如,使用div
标记