zoukankan      html  css  js  c++  java
  • JavaScript函数传参

    函数传参一:

    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <style type="text/css">
        #div1 {
            width: 100px;
            height: 100px;
            background:red;
        }
    </style>
    <script>
        function setcolor(color)
        {
            var odiv=document.getElementById('div1');
            odiv.style.background=color;
        }
    </script>
    </head>
    
    <body id="div1">
    <input type="button" value="黄色" onClick="setcolor('yellow')" />
    <input type="button" value="绿色" onClick="setcolor('green')" />
    </body>
    </html>

     函数传参二:

    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <style type="text/css">
        #div1 {
            width: 100px;
            height: 100px;
            background: red;
        }
    </style>
    <script>
        function setstyle(a,b)
        {
            var odiv=document.getElementById('div1');
            odiv.style[a]=b;
        }
    </script>
    </head>
    
    <body>
    <input type="button" value="变宽" onClick="setstyle('width','300px')" />
    <input type="button" value="变高" onClick="setstyle('height','300px')" />
    <input type="button" value="变色" onClick="setstyle('background','green')" />
    <div id="div1"></div>
    </body>
    </html>
  • 相关阅读:
    WebView
    dpdpipxptem单位长度理解
    js跨域访问
    JS&CSS压缩工具YUICompressor
    IIS7.5站点配置
    Jscript运行时错误:没有权限
    控制HttpContext为null
    JSON数组成员反序列化
    Linux 系统默认运行级别设定
    环境搭建常用工具
  • 原文地址:https://www.cnblogs.com/xinlvtian/p/7874598.html
Copyright © 2011-2022 走看看