JS备忘

最近在写公司的打卡考勤系统,需要用到js,由于没有系统学过,碰到新的知识点就记下来,以便复盘。


$("tr[id^='code']");//id属性以code开始的所有input标签

$("tr[id$='code']");//id属性以code结束的所有input标签

$("tr[id*='code']");//id属性包含code的所有input标签

可以联想到正则表达式也有^开头,$结尾,^就是以什么开头的意思,$以什么结尾。


html向js方法传递参数:

方法一:这个方法ie可行,其他浏览器没有响应。

<html>
    <head>
        <title> New Document </title>
        <script>
            function func(dd){
                alert(dd);
            }
            function fun(pp){
                alert(pp);
            }
        </script>
    </head> 
  <body>
      <input type="text" name="ddd">  
      <input type="button" value="submit" onclick="func(ddd.value)">
      <input type="text" name="pp"  onblur="fun(pp.value)">
  </body>
</html>

方法二:用event方式/对象传递

<html>
    <head>
    <script>
        function bbb(event){
        event = window.event || event;
        var srcEle = event.target || event.srcElement;
        alert(srcEle.value);
      }
        
        function ccc(cc){
            alert(cc.value);
        } 
    </script>
    </head>
    <body>
        <input type="text" value="by event"  οnblur="bbb()"/> 
        <input type="text" value="by object"  οnblur="ccc(this)"/>
    </body>
</html>

js点击事件总报错onclick is not defined错误


1

1

原文地址:https://www.cnblogs.com/jszfy/p/11150597.html