为了账号安全,请及时绑定邮箱和手机立即绑定

第五个没有反应,求救各位老师,前辈

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />

<title>javascript</title>

<style type="text/css">

body{font-size:12px;}

#txt{

    height:400px;

    width:600px;

border:#333 solid 1px;

padding:5px;}

p{

line-height:18px;

text-indent:2em;}

</style>

</head>

<body>

  <h2 id="con">JavaScript课程</H2>

  <div id="txt" class="abc"> 

     <h5>JavaScript为网页添加动态效果并实现与用户交互的功能。</h5>

        <p>1. JavaScript入门篇,让不懂JS的你,快速了解JS。</p>

        <p>2. JavaScript进阶篇,让你掌握JS的基础语法、函数、数组、事件、内置对象、BOM浏览器、DOM操作。</p>

        <p>3. 学完以上两门基础课后,在深入学习JavaScript的变量作用域、事件、对象、运动、cookie、正则表达式、ajax等课程。</p>

  </div>

  <form>

  <!--当点击相应按钮,执行相应操作,为按钮添加相应事件-->

    <input type="button" value="改变颜色" onclick="changeclor()">  

    <input type="button" value="改变宽高" onclick="changeihg()">

    <input type="button" value="隐藏内容" onclick="changedcs()">

    <input type="button" value="显示内容" onclick="changetgd()">

    <input type="button" value="取消设置" onClick="hey()">

  </form>

  <script type="text/javascript">

//定义"改变颜色"的函数

function changeclor(){

var changClor=document.getElementById("txt");

var changbg=document.getElementById("con");

changClor.style.color="blue";

changbg.style.backgroundColor="grey";}

//定义"改变宽高"的函数

function changeihg(){

var changh=document.getElementById("txt");

changh.style.height="500px";

var changw=document.getElementById("txt");

changw.style.width="700px";}

//定义"隐藏内容"的函数

function changedcs(){

var hideen=document.getElementById('txt');

hideen.style.display="none";}


//定义"显示内容"的函数

function changetgd(){

var shou=document.getElementById("txt");

shou.style.display="block";}

//定义"取消设置"的函数

function hey(){

    var reutnb=confirm("取消吗");

   if(reutnb==true){

       changClor.style.color="blue";

      changh.style.height="500px";

   }

   else{

      reutnb.className="abc";

   }

}


正在回答

8 回答

主要是因为changClor和changh这两个对象是在changeclor()函数内定义的。用我下面这个就没问题了

function cancel(){	var can=confirm("是否取消设置");	if(can){		var re=document.getElementById("txt");		re.removeAttribute('style');	}}


0 回复 有任何疑惑可以回复我~

能帮我看一下这是哪错了吗,第三四五个功能都运行不出来,谢谢



<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
<title>javascript</title>
<style type="text/css">
body{font-size:12px;}
#txt{
    height:400px;
    width:600px;
 border:#333 solid 1px;
 padding:5px;}
p{
 line-height:18px;
 text-indent:2em;}
</style>
</head>
<body>
  <h2 id="con">JavaScript课程</H2>
  <div id="txt">
     <h5>JavaScript为网页添加动态效果并实现与用户交互的功能。</h5>
        <p>1. JavaScript入门篇,让不懂JS的你,快速了解JS。</p>
        <p>2. JavaScript进阶篇,让你掌握JS的基础语法、函数、数组、事件、内置对象、BOM浏览器、DOM操作。</p>
        <p>3. 学完以上两门基础课后,在深入学习JavaScript的变量作用域、事件、对象、运动、cookie、正则表达式、ajax等课程。</p>
  </div>
  <form>
  <!--当点击相应按钮,执行相应操作,为按钮添加相应事件-->
    <input type="button" value="改变颜色" onclick=add()> 
    <input type="button" value="改变宽高" onclick=add1()>
    <input type="button" value="隐藏内容" oncilck=add2()>
    <input type="button" value="显示内容" oncilck=add3()>
    <input type="button" value="取消设置" oncilck=add4()>
  </form>
  <script type="text/javascript">
//定义"改变颜色"的函数
var kxf = document.getElementById("txt");
 function add(){
      kxf.style.color="red";
      kxf.style.backgroundColor="#ccc";
    }
//定义"改变宽高"的函数
function add1(){
    kxf.style.width="500px";
    kxf.style.height="500px";
}
//定义"隐藏内容"的函数
function add2(){
kxf.style.display="none";
}
//定义"显示内容"的函数
function add3(){
kxf.style.display="block";
}
//定义"取消设置"的函数
function add4(){
        if(confirm("是否取消所有设置")==true){
            kxf.style.color = "#000000";
            kxf.style.width = "600px";
            kxf.style.display = "block";
        }
   }
  </script>
</body>
</html>

0 回复 有任何疑惑可以回复我~
#1

qq_Cross_heart_0

兄弟,从第三个按钮写错了啊,下面没问题,onclick.你写的是oncilck.看仔细点。
2019-05-31 回复 有任何疑惑可以回复我~

/*哦,我收回刚才说的话,不是调用的问题,你复制代码的时候丢了最后两个标签,我没看见,你最后的hey函数没调用成功是因为你,没在函数里面声明变量,这是我按着你的思路给你改了一下,你看看。*/

<!DOCTYPE HTML>

<html>

<head>

    <meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />

    <title>javascript</title>

    <style type="text/css">

        body{font-size:12px;}

        #txt{

            height:400px;

            width:600px;

            border:#333 solid 1px;

            padding:5px;}

        p{

            line-height:18px;

            text-indent:2em;}

    </style>

</head>

<body>

<h2 id="con">JavaScript课程</H2>

<div id="txt" class="abc">

    <h5>JavaScript为网页添加动态效果并实现与用户交互的功能。</h5>

    <p>1. JavaScript入门篇,让不懂JS的你,快速了解JS。</p>

    <p>2. JavaScript进阶篇,让你掌握JS的基础语法、函数、数组、事件、内置对象、BOM浏览器、DOM操作。</p>

    <p>3. 学完以上两门基础课后,在深入学习JavaScript的变量作用域、事件、对象、运动、cookie、正则表达式、ajax等课程。</p>

</div>

<form>

    <!--当点击相应按钮,执行相应操作,为按钮添加相应事件-->

    <input type="button" value="改变颜色" onclick="changeclor()">

    <input type="button" value="改变宽高" onclick="changeihg()">

    <input type="button" value="隐藏内容" onclick="changedcs()">

    <input type="button" value="显示内容" onclick="changetgd()">

    <input type="button" value="取消设置" onClick="hey()">

</form>

<script type="text/javascript">

    //定义"改变颜色"的函数

    function changeclor(){

        var changClor=document.getElementById("txt");

        var changbg=document.getElementById("con");

        changClor.style.color="blue";

        changbg.style.backgroundColor="grey";}

    //定义"改变宽高"的函数

    function changeihg(){

        var changh=document.getElementById("txt");

        changh.style.height="500px";

        var changw=document.getElementById("txt");

        changw.style.width="700px";}

    //定义"隐藏内容"的函数

    function changedcs(){

        var hideen=document.getElementById('txt');

        hideen.style.display="none";}



    //定义"显示内容"的函数

    function changetgd(){

        var shou=document.getElementById("txt");

        shou.style.display="block";}

    //定义"取消设置"的函数

    function hey(){

        var reutnb=confirm("取消吗");

   if(reutnb==true){
       var changClor=document.getElementById("txt");
       var changh=document.getElementById("txt");
       changClor.style.color="#333";
       changh.style.height="400";
       changClor.style.display="block";

   }

   else{

       reutnb.className="abc";

   }

    }
    </script>
</body>
</html>


0 回复 有任何疑惑可以回复我~

兄dei,你发的代码不只是第五个按钮不好使,所有的都用不了,里面有的符号还是中文符号,你好好检查检查,另外你没运行成功的原因是因为你的变量问题,你把声明写都函数里面,他只作用到当前函数,然后你在第一个函数写了一个声明,在最后一个函数又重复声明,就会报错,你要么把声明拿出来,要么放到第一个函数的声明不要尝试在其他函数里面调用,那是调不到的。

0 回复 有任何疑惑可以回复我~
//你直接复制参考下我的代码
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
    <title>javascript</title>
    <style type="text/css">
        body{font-size:12px;}
        #txt{
            height:400px;
            width:600px;
            border:#333 solid 1px;
            padding:5px;}
        p{
            line-height:18px;
            text-indent:2em;}

    </style>
</head>
<body>
<h2 id="con">JavaScript课程</H2>
<div id="txt">
    <h5>JavaScript为网页添加动态效果并实现与用户交互的功能。</h5>
    <p>1. JavaScript入门篇,让不懂JS的你,快速了解JS。</p>
    <p>2. JavaScript进阶篇,让你掌握JS的基础语法、函数、数组、事件、内置对象、BOM浏览器、DOM操作。</p>
    <p>3. 学完以上两门基础课后,在深入学习JavaScript的变量作用域、事件、对象、运动、cookie、正则表达式、ajax等课程。</p>
</div>
<form>
    <!--当点击相应按钮,执行相应操作,为按钮添加相应事件-->
    <input type="button" value="改变颜色" onclick="col()">
    <input id="btnW" type="button" value="改变宽高" onclick="wid()">
    <input id="btnH" type="button" value="隐藏内容" onclick="hid()">
    <input id="btnB" type="button" value="显示内容" onclick="blo()">
    <input id="btnCan" type="button" value="取消设置" onclick="cancel()" >
</form>
<script type="text/javascript">
    var oCon = document.getElementById("con");
    var oTxt = document.getElementById("txt");
    //定义"改变颜色"的函数
    function col(){
        oTxt.style.color = "red";
    }
    //定义"改变宽高"的函数
    function wid(){
        oTxt.style.width = "300px";
    }
    //定义"隐藏内容"的函数
    function hid(){
        oTxt.style.display = "none";
    }
    //定义"显示内容"的函数
    function blo(){
        oTxt.style.display = "block";
    }
    //定义"取消设置"的函数
    function cancel(){
        if(confirm("是否取消所有设置")==true){
            oTxt.style.color = "#000000";
            oTxt.style.width = "600px";
            oTxt.style.display = "block";
        }
    }


</script>
</body>
</html>


0 回复 有任何疑惑可以回复我~
#1

weixin_慕移动6257819

if(confirm("是否取消所有设置")==true),confirm("是否取消所有设置")不是自带真假值,干嘛还去判断真假?
2019-05-29 回复 有任何疑惑可以回复我~

你的://定义"隐藏内容"的函数的 txt用的单引号改成双引号

0 回复 有任何疑惑可以回复我~
#1

慕移动8517387

双或单没事的,并不影响最终的输出
2019-06-13 回复 有任何疑惑可以回复我~

等我做完就来回答你 我也是0基础在学习

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

第五个没有反应,求救各位老师,前辈

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信