zoukankan      html  css  js  c++  java
  • jQuery 常用getter&setter

    .attr&.prop

    asGet:Get the value of a property/an attribute for the first element in the set of matched elements.

    asSet:Set one or more  properties/attributes for the set of matched elements.

    Note:To retrieve and change DOM properties such as the checkedselected, or disabled state of form elements, use the .prop() method

    e.g:

    //suppose ele is a checkbox
    if(ele.checked)
    if(ele.prop('checked'))
    if(ele.is(':checked'))

      .css

    asGet:Get the computed style properties for the first element in the set of matched elements.

    asSet:Set one or more CSS properties for the set of matched elements.

    .toggleClass() : Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the state argument.

    .addClass()

    .removeClass()

    .hasClass()

    .val()

    asGet:Get the current value of the first element in the set of matched elements.

    asSet:Set the value of each element in the set of matched elements.

    .text()

    asGet:Get the combined text contents of each element in the set of matched elements, including their descendants.

    asSet:Set the content of each element in the set of matched elements to the specified text.

    .html()

    asGet:Get the HTML contents of the first element in the set of matched elements.

    asSet:Set the HTML contents of each element in the set of matched elements.

    .offset()

    asGet:Get the current coordinates of the first element in the set of matched elements, relative to the document.

    asSet:Set the current coordinates of every element in the set of matched elements, relative to the document.

    Note:The .offset() method allows us to retrieve the current position of an element (specifically its border box, which excludes margins) relative to the document.Contrast this with .position(), which retrieves the current position relative to the offset parent.

    position()返回相对于父元素的偏移量

    width()height()获得元素的宽高,不包括内外边距及边框,设置时会受到盒模型的影响

    innerWidth()innerHeight()包含内边距

    outerWidth()outerHieght()包含内边距及边框

    scrollTop()scrollLeft()获得或设置元素滚动条的位置

    .data()

    asGet: Set Return the value at the named data store for the first element in the jQuery collection, as set by data(name, value) or by an HTML5 data-* attribute.

    asSet: Store arbitrary(任意的) data associated with the matched elements.

    Note:Using the object directly to get or set values is faster than making individual calls to .data() to get or set each value:

    var mydata = $( "#mydiv" ).data();
    if ( mydata.count < 9 ) {
      mydata.count = 43;
      mydata.status = "embiggened";
    }
  • 相关阅读:
    dotnet 网络编程 tcp
    sql_index 索引测试
    精美诗文
    mssql常用语句,平时用来学习sql的
    dotnet 线程同步
    DotNet 序列化
    2、董事长千金诱拐事件
    十三、动态创建元素
    1、云霄飞车杀人事件
    十二、内容过滤器,可见性过滤器,属性过滤器,子元素过滤器,表单类别过滤器,表单属性过滤器
  • 原文地址:https://www.cnblogs.com/goOtter/p/9533582.html
Copyright © 2011-2022 走看看