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系统调优方法
    递归(Recursion)算法
    数据结构之链表
    【日常摸鱼】牛客挑战赛2
    【日常摸鱼】牛客挑战赛1
    组合计数学习笔记1
    To-Do List 2
    20199112 2019-2020-2 《网络攻防实践》第 3 周作业
    Flutter上线项目实战——腾讯点播直播下载
    打开旧Flutter项目说:Your Flutter application is created using an older version of the Android embedding
  • 原文地址:https://www.cnblogs.com/wanghuanl/p/9063942.html
Copyright © 2011-2022 走看看