zoukankan      html  css  js  c++  java
  • JavaScript之实例

      <meta charset="UTF-8">
      <meta http-equiv="x-ua-compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>定时器</title>
      <script>
        var intervalId;
    
        function f() {
          var timeStr = (new Date()).toLocaleString();
          var inputEle = document.getElementById("i1");
          inputEle.value = timeStr;
        }
    
        function start() {
          f();
          if (intervalId === undefined) {
            intervalId = setInterval(f, 1000);
          }
        }
        function end() {
          clearInterval(intervalId);
          intervalId = undefined;
        }
    
      </script>
    </head>
    <body>
    
    <input type="text" id="i1">
    <input type="button" value="开始" id="start" onclick="start();">
    <input type="button" value="结束" id="end" onclick="end();">
    </body>
    </html>
    刷新时间
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>搜索框示例</title>
    
    </head>
    <body>
        <input id="d1" type="text" value="请输入关键字" onblur="blurs()" onfocus="focus()">
        
    <script>
    function focus(){
        var inputEle=document.getElementById("d1");
        if (inputEle.value==="请输入关键字"){
            inputEle.value="";
        }
    }
    
    function blurs(){
        var inputEle=document.getElementById("d1");
        var val=inputEle.value;
        if(!val.trim()){
            inputEle.value="请输入关键字";
        }
    }
    </script>
    </body>
    </html>
    搜索框
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="x-ua-compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>select联动</title>
    </head>
    <body>
    <select id="province">
      <option>请选择省:</option>
    </select>
    
    <select id="city">
      <option>请选择市:</option>
    </select>
    
    <script>
      data = {"河北省": ["廊坊", "邯郸"], "北京": ["朝阳区", "海淀区"], "山东": ["威海市", "烟台市"]};
    
      var p = document.getElementById("province");
      var c = document.getElementById("city");
    
      for (var i in data) {
        var optionP = document.createElement("option");
        optionP.innerHTML = i;
        p.appendChild(optionP);
      }
      p.onchange = function () {
        var pro = (this.options[this.selectedIndex]).innerHTML;
        var citys = data[pro];
        // 清空option
        c.options.length = 0;
    
        for (var i=0;i<citys.length;i++) {
          var option_city = document.createElement("option");
          option_city.innerHTML = citys[i];
          c.appendChild(option_city);
        }
      }
    </script>
    </body>
    </html>
    select联动菜单
  • 相关阅读:
    201. Bitwise AND of Numbers Range
    200.Number of Islands
    199. Binary Tree Right Side View
    198. House Robber
    191. Number of 1 Bits
    190. Reverse Bits
    odoo pivot filed字段设置
    postgres 实现查找所有的子记录,child_of
    postgres 查询返回记录集的函数
    python GUI编程/窗口编程之easygui
  • 原文地址:https://www.cnblogs.com/fu-yong/p/8561752.html
Copyright © 2011-2022 走看看