Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按钮操作的多个任务之一';不执行_Javascript_Html_Script Tag - Fatal编程技术网

Javascript 按钮操作的多个任务之一';不执行

Javascript 按钮操作的多个任务之一';不执行,javascript,html,script-tag,Javascript,Html,Script Tag,我在一个按钮执行多个任务时遇到问题。该按钮执行三个任务中的两个(在(单击)时隐藏它们),最后一个任务除外,即文本闪烁javascript函数。我看不出有什么可能是错的!之前隐藏文本的语法与隐藏下一个文本的语法相同,但由于某些原因,它不会隐藏文本(闪烁文本)。提前感谢您的帮助 这是我的密码: <!DOCTYPE html> <html> <head> <style> body { background-color: coral; co

我在一个按钮执行多个任务时遇到问题。该按钮执行三个任务中的两个(在
(单击)
时隐藏它们),最后一个任务除外,即文本闪烁javascript函数。我看不出有什么可能是错的!之前隐藏文本的语法与隐藏下一个文本的语法相同,但由于某些原因,它不会隐藏文本(闪烁文本)。提前感谢您的帮助

这是我的密码:

<!DOCTYPE html>
<html>
<head>
<style>
body {
    background-color: coral;
    color: white;
}

.text1{
 padding-left: 15px;
 color: white; 
 font-family: 'Orbitron', sans-serif;
 width: 250px;
 float: left;
 padding-top: 10px;
}


.text2{
  color: white;
  width: 100px;
  float: right;
  padding-top: 10px;
}


</style>
<link rel="stylesheet" href="styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(".btn1").on('click',function(){
      $("p").hide();
      $(".text1").hide();
      $(".text2").hide();
      $('body').css("background", "black");  

    });

    var element = $(".text2");
    var shown = true;
    setInterval(toggle, 500);

    function toggle() {
     if(shown) {
        element.hide();
     } else {
        element.show();
     }
    shown = !shown;
  }


});
</script>

</head>
<body>
  <div class="text1">
  PRESS BUTTONS BELOW
  </div>
  <div class="text2">-- : --</div>  
  <button class="btn1">online</button>
</body>
</html>

身体{
背景颜色:珊瑚;
颜色:白色;
}
.text1{
左侧填充:15px;
颜色:白色;
字体系列:“Orbitron”,无衬线;
宽度:250px;
浮动:左;
填充顶部:10px;
}
.text2{
颜色:白色;
宽度:100px;
浮动:对;
填充顶部:10px;
}
$(文档).ready(函数(){
$(“.btn1”)。在('click',function()上{
$(“p”).hide();
$(“.text1”).hide();
$(“.text2”).hide();
$('body').css(“背景”、“黑色”);
});
var元素=$(“.text2”);
显示的var=真;
设置间隔(切换,500);
函数切换(){
如图所示{
元素。隐藏();
}否则{
元素show();
}
显示=!显示;
}
});
按下下面的按钮
-- : --  
在线 的

隐藏
.text2
使用
clearInterval
清除
setInterval

$(文档).ready(函数(){
$(“.btn1”)。在('click',function()上{
$(“p”).hide();
$(“.text1”).hide();
$(“.text2”).hide(函数(){
净空间隔(x)
});
$('body').css(“背景”、“黑色”);
});
var元素=$(“.text2”);
显示的var=真;
var x=设置间隔(切换,500);
函数切换(){
如图所示{
元素。隐藏();
}否则{
元素show();
}
显示=!显示;
}
});
正文{
背景颜色:珊瑚;
颜色:白色;
}
.text1{
左侧填充:15px;
颜色:白色;
字体系列:“Orbitron”,无衬线;
宽度:250px;
浮动:左;
填充顶部:10px;
}
.text2{
颜色:白色;
宽度:100px;
浮动:对;
填充顶部:10px;
}

按下下面的按钮
-- : --

联机
隐藏
.text2
使用
clearInterval
清除
setInterval

$(文档).ready(函数(){
$(“.btn1”)。在('click',function()上{
$(“p”).hide();
$(“.text1”).hide();
$(“.text2”).hide(函数(){
净空间隔(x)
});
$('body').css(“背景”、“黑色”);
});
var元素=$(“.text2”);
显示的var=真;
var x=设置间隔(切换,500);
函数切换(){
如图所示{
元素。隐藏();
}否则{
元素show();
}
显示=!显示;
}
});
正文{
背景颜色:珊瑚;
颜色:白色;
}
.text1{
左侧填充:15px;
颜色:白色;
字体系列:“Orbitron”,无衬线;
宽度:250px;
浮动:左;
填充顶部:10px;
}
.text2{
颜色:白色;
宽度:100px;
浮动:对;
填充顶部:10px;
}

按下下面的按钮
-- : --

在线
非常感谢!所以
clearInterval(x)
基本上释放了保持
#text2
闪烁的循环?对吗?非常感谢!所以
clearInterval(x)
基本上释放了保持
#text2
闪烁的循环?对的