zoukankan      html  css  js  c++  java
  • JQuery $ 应用手记 (持续更新中)

    JavaScript

    JQuery

    注册事件

       

    <asp:Button ID="button" Text="按钮" runat="server"

    OnClientClick="javascript:ClickEvent();" />

    $("#<%=button.ClientID %>").click(isClick);

    $("#<%=button.ClientID %>").blur(isBlur);

         

    或者

         

    $("#<%=button.ClientID %>").blur(function(){

    isBlur();

    });

       

    获取控件ID

       

    document.getElementById('trRemark')

    $("#trRemark")

    获取服务器控件ID

       

    document.getElementById('<%= button.ClientID%>')

    $("#<%=button.ClientID %>")

    显示、隐藏HtmlElements

       

    document.getElementById("tr").style("display","inline");

    document.getElementById("tr").style("display","none");

    $("#tr").show();

    $("#tr").hide();

    $("#tr").toggle();

    获取值\文本

       

    document.getElementById("txt").value

    document.getElementById("txt").innertext

       

    $("#<%= txt.ClientID%> ").val()

    $("#<%= txt.ClientID%> ").text()

    $("#<%=DropDownList.ClientID %> option:selected").text()

    Array

       

    var arr = new Array();

    arr[0] = "A";

    arr[1]=b;

    arr[2]="c";

    var arr = ["A",b,"c"];

    判断Array中是否有false

       

     for (var i = 0; i < entryArray.length; i++) {

                        if (entryArray[i] == false) {

                            flag = false;

                            break;

                        }

                    }

                    if (flag == false) {

                       //TODO

                    }

       

    If ($.inArray("false",entryArray) != -1) {

    //TODO

    }

       

    判断是否对象是undefined

       

    typeof (document.getElementById('trRemark ')) != "undefined"

    typeof trRemark != 'undefined'

    加载样式

       

       

    $("#<%=button.ClientID %>").css("borderColor", "red");

    对元素进行赋值

       

    document.getElementById("textbox").value = "1234";

    $("#textBox").val("1234");

    IndexOf

       

    JS包含关系

    indexOf()方法

    如果返回>=0则表明包含,否则不包含

    var a="TestHelloWord";

    document.write(a.indexOf("Hello"));

       

    $("#textBox").val().indexOf("Hello") < 0

      发现包装元素集合的add()比较不错
    解决我早前的一个疑问:
    $("#<%=button1.ClientID %>").click(ClickEvent);
    $("#<%=button2.ClientID %>").click(ClickEvent);
    $("#<%=button3.ClientID %>").click(ClickEvent);
    以上这三个按钮的事件都是一样的。
    我不每次都这样写。那如何简化一下呢
    使用add()
    $("#<%=button1.ClientID %>")
    .add("#<%=button2.ClientID %>")
    .add("#<%=button3.ClientID %>")
    .click(ClickEvent);

        

  • 相关阅读:
    ngx-bootstrap使用04 carousel组件
    ngx-bootstrap使用03 Alerts组件、利用Object.assign复制对象
    ngx-bootstrap使用02 Accordion组件的使用
    ngx-bootstrap使用01 安装ngx-bootstrap和bootstrap及其使用、外部样式引入
    SpringBoot11 读取properties文件、发送邮件
    SpringBoot10 整合JSP
    SpringBoot09 自定义servlet、注册自定义的servlet、过滤器、监听器、拦截器、切面、webmvcconfigureradapter过时问题
    红帽系统制作yum本地源
    利用python数据分析panda学习笔记之基本功能
    利用python数据分析panda学习笔记之DataFrame
  • 原文地址:https://www.cnblogs.com/RuiLei/p/1540778.html
Copyright © 2011-2022 走看看