zoukankan      html  css  js  c++  java
  • with语句,prompt弹窗及小部分正则表达式

    这周学校课程比较多,自己也没有挤出来时间去学习。所以相对也没有学到多少东西。遇到了一个难题,所幸已经解决了。

    第一个:with()语句,当需要重复输入一段代码的一部分时可以用with()语句来减少部分代码的书写次数。

    然后还有一个弹窗prompt,可以输入一些文字。

    <script>
    //  var age = prompt('请输入你的年级',"");
    //  alert(age);
    //  document.getElementById("demo1").style.borderColor="red";
    //  document.getElementById("demo1").style.borderWidth="1px";
    //  document.getElementById("demo1").style.borderStyle="solid";
    //  document.getElementById("demo1").style.width="200px";
    //  document.getElementById("demo1").style.height="100px";
    //替代括号里的字段,不再重新输入。
      with(document.getElementById("demo1").style){
       borderColor="red";
       borderWidth="1px";
       borderStyle="solid";
       height="100px";
       width="200px";
      }
      </script>

    最后正则表达式:

    <script type="text/javascript">
       var part1=new RegExp("hello");//写法一
       var part2=/world/;//写法二。作用:用此正则表达式来匹配数据,找到等于world的
       var pat=/my/g;
       var str="this is my coat...";
       console.log(pat.test(str));//test 检测是否有指定值,有的话返回值为true,没有的话返回值为false
       
       console.log(pat.exec("this toy beer is my favotite toy"));
       document.write(str.lastIndex)
       var a="xiaoming say:hello madam.the madam say:hello,xiaoming."
       var b=/xiaoming/ig;
       console.log(a.match(b));
       
      </script>

    正则表达式的描述有点少,比较难懂一点。

  • 相关阅读:
    linux UID,GID,EUID,EGID,SUID,SGID
    Hard模式题目
    【Todo】Java TreeSet学习 & ceiling,floor
    被信号打断的系统调用
    拟牛顿法——变种及其相互关系
    域名注册查询接口(API)的说明
    HDU 2825 Wireless Password(AC自动机+状压DP)
    串的模式匹配
    Android DES加密的CBC模式加密解密和ECB模式加密解密
    [Web Chart系列之五] 6. 实战draw2d之ConnectionRouter
  • 原文地址:https://www.cnblogs.com/wanghuanl/p/9063942.html
Copyright © 2011-2022 走看看