agruments应用——求出函数参数的总合&&css函数——设置/读取对象的属性&&当前输入框高亮显

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>agruments应用——求出函数参数的总合</title>
<style>
pre{color:green;padding:10px 15px;background:#f0f0f0;border:1px dotted #333;font:12px/1.5 Courier New;}
span{color:#999;}
</style>
</head>
<body>
<pre>
&lt;script type="text/javascript"&gt;
    var i = iResult = 0
    function sum()
    {
        for (var i = 0; i < arguments.length; i++)
        {
            iResult += arguments[i]
        }
        return iResult
    }
    <span>//应用</span>
    alert(sum(1,2,3,4,5,6,7,8,9,10)) <span>//输出55</span>
&lt;/script&gt;
</pre>
<script type="text/javascript">
var i = iResult = 0
function sum()
{
    for (var i = 0; i < arguments.length; i++)
    {
        iResult += arguments[i]
    }
    return iResult
}
//应用
alert(sum(1,2,3,4,5,6,7,8,9,10))
</script>
</body>
</html>
css函数——设置/读取对象的属性
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>css函数——设置/读取对象的属性</title>
<style>
div{width:400px;height:200px;background:#fef4eb;border:1px solid #f60;margin:0 auto;}
input{border:0;color:#fff;cursor:pointer;font-weight:700;background:#f60;padding:2px 4px;margin:10px 0 0 10px;}
</style>
<script type="text/javascript">
function css(obj, attr, value)
{
    switch (arguments.length)
    {
        case 2:
            if(typeof arguments[1] == "object")
            {    //二个参数, 如果第二个参数是对象, 批量设置属性
                for (var i in attr)obj.style[i] = attr[i]
            }
            else
            {    //二个参数, 如果第二个参数是字符串, 读取属性值
                return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj, null)[attr]
            }
            break;
        case 3:
            //三个参数, 单一设置属性
            obj.style[attr] = value;
            break;
        default:
            alert("参数错误!")
    }
}
window.onload = function ()
{
    var oBox = document.getElementById("box");
    var aInput = oBox.getElementsByTagName("input");

    //第一个按钮点击事件
    aInput[0].onclick = function ()
    {
        //两个参数, 第二个参数为字符串, 读取属性值
        alert("width: " + css(oBox, "width") + "\nheight: " + css(oBox, "height") + "\nbackground-color: " + css(oBox, "backgroundColor"))
    };
    //第二个按钮点击事
    aInput[1].onclick = function ()
    {
        //两个参数, 第二个参数为对象, 属性批量设置
        css(oBox, {width: "330px", height: "100px", borderColor: "#0084ff", backgroundColor: "#eff8ff"});
        //三个参数, 属性单一设置
        for (i = 0; i < aInput.length; i++) css(aInput[i], "backgroundColor", "#0084ff")
    }
    //第三个按钮点击事件
    aInput[2].onclick = function ()
    {
        //两个参数, 第二个参数为对象, 属性批量设置
        css(oBox, {width: "400px", height: "200px", borderColor: "#f60", backgroundColor: "#fef4eb"});
        //三个参数, 属性单一设置
        for (i = 0; i < aInput.length; i++) css(aInput[i], "backgroundColor", "#f60")
    }
};
</script>
</head>
<body>
<div id="box">
    <input type="button" value="Get Style" /><input type="button" value="Set Style" /><input type="button" value="Default Style" />
</div>
</body>
</html>
当前输入框高亮显
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>当前输入框高亮显示</title>
<style>
body,form,h2,p,input{margin:0;padding:0;}
body{color:#4f4f4f;font:14px/1.5 \5fae\8f6f\96c5\9ed1;}
form{width:400px;background:#fef4eb;border:2px solid #f60;padding-bottom:10px;overflow:hidden;zoom:1;margin:10px auto;}
form h2{color:#fe791e;font-size:16px;background:#ffebd7;border-bottom:2px solid #f60;padding:5px 10px;}
form p{float:left;clear:both;width:100%;height:31px;margin-top:10px;line-height:31px;}
form label,form input{float:left;}
form label{width:100px;height:31px;text-align:right;}
form input{border:0;font-family:\5fae\8f6f\96c5\9ed1;background:url(img/input.png) no-repeat;}
form .f-text,form .f-text-high{width:203px;height:31px;padding-left:5px;line-height:31px;}
form .f-text-high{background-position:0 -31px;}
form .f-btn{color:#fff;width:104px;height:31px;cursor:pointer;font-size:16px;background:#f60;line-height:31px;border-radius:5px;}
</style>
<script type="text/javascript">
window.onload = function ()
{
    var aInput = document.getElementsByTagName("input");
    var i = 0;
    for (i = 0; i < aInput.length - 1; i++)
    {
        aInput[i].onfocus = function ()
        {
            this.className = "f-text-high"
        };
        aInput[i].onblur = function ()
        {
            this.className = "f-text"
        }
    }
};
</script>
</head>
<body>
<form>
    <h2>用户登录</h2>
    <p><label>用户名:</label><input class="f-text" type="text" /></p>
    <p><label>密码:</label><input class="f-text" type="password" /></p>
    <p><label></label><input class="f-btn" type="button" value="登 录" /></p>
</form>
</body>
</html>
时间: 2024-12-13 09:24:22

agruments应用——求出函数参数的总合&&css函数——设置/读取对象的属性&&当前输入框高亮显的相关文章

利用非线性回归,梯度下降法求出学习参数θ,进而求得Cost函数最优值——Jason niu

import numpy as np import random def genData(numPoints,bias,variance): x = np.zeros(shape=(numPoints,2)) y = np.zeros(shape=(numPoints)) for i in range(0,numPoints): x[i][0]=1 x[i][1]=i y[i]=(i+bias)+random.uniform(0,1)%variance return x,y def gradie

关于ECMAScript函数参数的多方面理解

写在前面 无论在哪种编程语言中,函数都是特别有意思的部分,但同时也是一个难点.在ECMAScript中,作为对象的函数也不例外,让人又爱又恨.这一章我们主要从多个方面聊一聊函数参数这一部分,至于函数像海一样深的其他部分我们有机会再聊. 函数的有些知识点是比较简单的,所以在进入正题之前,我们先简单介绍两点:函数的return和函数的重载,因为函数的重载需要arguments的知识,所以我们最后来理解函数的重载. 章节结构如下: 函数的return 函数参数 函数的重载 注:如没有另外说明,文中的函

逆向知识十一讲,识别函数的调用约定,函数参数,函数返回值.

逆向知识十一讲,识别函数的调用约定,函数参数,函数返回值. 在反汇编中,我们常常的会看到各种的函数调用,或者通过逆向的手段,单独的使用这个函数,那么此时,我们就需要认识一下怎么识别函数了. 一丶识别__cdecl 函数(俗称C Call),函数参数,函数返回值 首先写一个C Call的函数 1.返回值 int类型, 参数int 类型 高级代码: int __cdecl MyAdd(int a,int b) { return a + b; } int main(int argc, char* ar

ES6函数参数默认值作用域的模拟原理实现与个人的一些推测

一.函数参数默认值中模糊的独立作用域 我在ES6入门学习函数拓展这一篇博客中有记录,当函数的参数使用默认值时,参数会在初始化过程中产生一个独立的作用域,初始化完成作用域会消失:如果不使用参数默认值,不会产生这个作用域:产生疑问是因为这段代码: var x = 1; function foo(x, y = function () {x = 2;}) { var x = 3; y(); console.log(x); }; foo();//3 foo(4);//3 console.log(x);//

C/C++语言中的函数参数传参三种对比

学了很长时间C/C++有时指针方面还是有点乱. 希望大神发现如果下面有不对的地方请指出.我发现之所以我乱就是因为中文表述不准确的问题,比如 ,地址值和地址 #include <iostream> #include <string> using namespace std; void swap1(string* str1,string* str2){// 1.对象指针作为函数参数 //影响实参 cout<<&str1<<" "<

数组作为函数参数

一.一维数组名作函数参数 用数组名作函数参数,应该在主调函数和被调函数分别定义数组,例如 <span style="font-size:18px;">void main() { void f(int b[10]);//void f(int b[]) int a[10]; f(a); }</span> 在被调用函数中声明了形参数组的大小为10,但在实际中,指定其大小是不起任何作用的,因为C语言编译对形参数组大小不做检查,只将实参数组的首元素地址传给形参数组.形参数

[C++程序设计]用数组名作函数参数

1. 用数组元素作函数实参 1 #include <iostream> 2 using namespace std; 3 4 int max_value(int x, int max) 5 { 6 return max > x ? max : x; 7 } 8 9 int main() 10 { 11 const int x = 3, y = 4; 12 int a[x][y]={{34,62,34,101},{45,67,3,0},{11,45,97,100}}; 13 int max

数组名做函数参数

数组名做函数参数 用数组名做函数参数与用数组元素作实参有几点不同: (1)用数组元素作实参时,只要数组类型和函数的形参变量的类型一致,那么作为下标变量的数组元素的类型也和函数形参变量的类型是一致的.因此,并不要求函数的形参也是下标变量.换句话说,对数组元素的处理是按普通变量对待的.用数组名作函数参数时,则要求形参和相应的实参都必须是类型相同的数组,都必须有明确的数组说明.当形参和实参两者类型不一致时,机会发生错误. (2)用普通变量或下标变量作函数参数时,形参变量和实参变量都是由编译系统分配的两

C++二维数组做函数参数

二维数组做函数参数的形式主要有: /对于一个m行n列int元素的二维数组 //函数f的形参形式 f(int daytab[m][n]) {...} //以下两种可以忽略行数 f(int daytab[][n]) {...} f(int (*daytab)[n]) {...} 这里都不能忽略第二维的大小.主要 原因是二维数组在栈内分配的内存是连续的,它的每一行都有相同的元素,这样,array[i][j] 和 *(*(array +i) +j)是一样的,程序是知道array+i的i实际上偏移了i*N