Javascript 函数不执行
Javascript Function Doesn’t Execute
这个简单的函数在调用时不会执行。当从函数中取出时,它 运行s 但不在函数中。是什么让函数达到 运行?
HTML
<img id = “hide” src = “mypic.jpg”>
Javascript
Function show {
var x = document.getElementById(“hide”);
x.style.display = “none”
}
show();
你的函数声明有误
Function show {
var x = document.getElementById(“hide”);
x.style.display = “none”
}
show();
应该写成:
function show() {
var x = document.getElementById('hide');
x.style.display = 'none';
}
show();
<img id ="hide" src ="https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" />
您的 javascript 中存在一些小问题,它应该如下所示:
function show() {
var x = document.getElementById(“hide”);
x.style.display = “none”;
}
show();
您的代码中缺少一些基础知识
"Function" 必须是 "function"
函数名必须带括号即 functionName(){};
你的函数声明必须是这样的
函数显示(){}
然后你必须在 onClick() 等事件上调用相同的函数
这是link你可以通过 JAVASCRIPT
希望这对您有所帮助...干杯!
这个简单的函数在调用时不会执行。当从函数中取出时,它 运行s 但不在函数中。是什么让函数达到 运行?
HTML
<img id = “hide” src = “mypic.jpg”>
Javascript
Function show {
var x = document.getElementById(“hide”);
x.style.display = “none”
}
show();
你的函数声明有误
Function show {
var x = document.getElementById(“hide”);
x.style.display = “none”
}
show();
应该写成:
function show() {
var x = document.getElementById('hide');
x.style.display = 'none';
}
show();
<img id ="hide" src ="https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" />
您的 javascript 中存在一些小问题,它应该如下所示:
function show() {
var x = document.getElementById(“hide”);
x.style.display = “none”;
}
show();
您的代码中缺少一些基础知识
"Function" 必须是 "function"
函数名必须带括号即 functionName(){};
你的函数声明必须是这样的 函数显示(){}
然后你必须在 onClick() 等事件上调用相同的函数
这是link你可以通过 JAVASCRIPT
希望这对您有所帮助...干杯!