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>

  • 相关阅读:
    二分题目
    求最小公倍数的最简模板
    用 vue 脚手架 vue-cli 初始化(新建)项目
    电脑没有声音
    node.js 安装步骤
    phpStrom编辑器 通过 git 提交代码到 gitlab
    jq 实现头像(气泡式浮动)
    微信网页授权 、获取用户昵称 头像等信息
    秒格式化 “秒” 为 天 时 分 秒
    改变swiper 按钮swiper-button-next 颜色
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1775783.html
Copyright © 2011-2022 走看看