zoukankan      html  css  js  c++  java
  • Javascript的this例子

    <!--这个程序使用了javascript中的this,this可以减少很多不必要的代码量,并且提高代码的效率-->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script language="javascript">
    function processData(form){
    for (var i = 0; i < form.Beatles.length; i++) {
    if (form.Beatles[i].checked) {
    break;
    }
    }
    var beatle = form.Beatles[i].value;
    var song = form.song.value;
    alert("Checking whether"+"   "+ song+"   "+ "features"+"   "+ beatle+"   "+ "...");
    }

    function verifySong(entry){//这里的entry是随便起的也可以叫别的名
    var song = entry.value;
    alert("Checking whether" +"   "+ song+"   " + "is a Beatles tune...");
    }
    </script>
    </head>
    <body>
    <form onSubmit="return false">
    Choose your favorite Beatle:
    <input type="radio" name="Beatles" value="John Lennon" checked/>John  <!--看到这里的checked了吧可以这样太简单了-->
    <input type="radio" name="Beatles" value="Paul McCartney"/>Paul
    <input type="radio" name="Beatles" value="George Harrison"/>George
    <input type="radio" name="Beatles" value="Ringo Starr"/>Ringo
    <p>
    Enter the name of your favorite Beatles song:
    <br>
    <input type="text" name="song" value="Eleanor Rigby" onChange="verifySong(this)"/>
    <p>
    <input type="button" name="process" value="Process Request..." onClick="processData(this.form)"/>
    <!--因为这个按钮是要提交表单的,直接将form传到指定的函数中-->
    </form>
    </body>
    </html>

  • 相关阅读:
    函数参数的讨论
    redirect-windows-cmd-stdout-and-stderr-to-a-single-file
    rust 多文件工程
    rust: 默认初始化,函数重载
    VSCode如何格式化所有文件
    FLV协议5分钟入门浅析
    WebRTC:数据传输相关协议简介
    WebSocket协议:5分钟从入门到精通
    Nodejs进阶:crypto模块中你需要掌握的安全基础知识
    前端进阶之路:如何高质量完成产品需求开发
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1775783.html
Copyright © 2011-2022 走看看