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>

  • 相关阅读:
    C# 文件类的操作---删除
    C#实现Zip压缩解压实例
    UVALIVE 2431 Binary Stirling Numbers
    UVA 10570 meeting with aliens
    UVA 306 Cipher
    UVA 10994 Simple Addition
    UVA 696 How Many Knights
    UVA 10205 Stack 'em Up
    UVA 11125 Arrange Some Marbles
    UVA 10912 Simple Minded Hashing
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1775783.html
Copyright © 2011-2022 走看看