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

仅供参考!

<form>
  <!--当点击相应按钮,执行相应操作,为按钮添加相应事件-->
    <input type="button" value="改变颜色" onclick = "updateColor()">  
    <input type="button" value="改变宽高" onclick = "updateWidthAndHeight()">
    <input type="button" value="隐藏内容" onclick = "hidingContent()">
    <input type="button" value="显示内容" onclick = "displayContent()">
    <input type="button" value="取消设置" onclick = "cancelSet()">
  </form>
  <script type="text/javascript">
//定义"改变颜色"的函数
    var txt_document = document.getElementById('txt');
    
    function updateColor(){
        txt_document.style.color = "green";
        txt_document.style.backgroundColor = "black";
    }

//定义"改变宽高"的函数
    function updateWidthAndHeight(){
        txt_document.style.width = "200px";
        txt_document.style.height = "300px";
    }

//定义"隐藏内容"的函数
    function hidingContent(){
        txt_document.style.display="none";
    }

//定义"显示内容"的函数
    function displayContent(){
        txt_document.style.display="block";
    }

//定义"取消设置"的函数
    function cancelSet(){
        var confirm_res = window.confirm("确定要取消设置吗?");
        if(confirm_res){
            txt_document.removeAttribute("style");
        }else{
            return false;
        }
    }

  </script>

正在回答

1 回答

add

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

举报

0/150
提交
取消
JavaScript入门篇
  • 参与学习       737859    人
  • 解答问题       9555    个

JavaScript做为一名Web工程师的必备技术,本教程让您快速入门

进入课程

仅供参考!

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