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>

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

  • 相关阅读:
    form表单 获取与赋值
    转:探讨JS合并两个数组的方法
    Extjs动态增删组件
    Extjs中创建Tree菜单【一】
    Extjs中grid前端分页使用PagingMemoryProxy【二】
    python模拟线性回归的点
    TensorFlow 辨异 —— tf.add(a, b) 与 a+b(tf.assign 与 =)、tf.nn.bias_add 与 tf.add(转)
    python使用cv2显示图片像素值
    tensorflow中run和eval的区别(转)
    获取tensorflow中tensor的值
  • 原文地址:https://www.cnblogs.com/wanghuanl/p/9063942.html
Copyright © 2011-2022 走看看