zoukankan      html  css  js  c++  java
  • jQuery的prop和attr方法之间区别

    JQuery.attr():
    Get the value of an attribute for the first element in the set of matched elements.

    JQuery. Prop():
    Gets the value of a property for the first element in the set of matched elements.

    Reference MSDN:
    for a checkbox (jquery 1.6+)
    <input id="check1" checked="checked" type="checkbox" />

    .attr('checked')     //returns checked
    .prop('checked')     //returns true
    .is(':checked')     //returns true

    Prop() method returns Boolean value for checked, selected, disabled, readOnly..and so on while attr returns defined string. So, you can directly use .prop("checked") in if condition. SelectedIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked, and defaultSelected..and so on should be retrieved and set with the .prop() method. These do not have corresponding attributes and are only properties. .attr() calls .prop() internally so .attr() method will be slightly slower than accessing them directly through .prop().

     
    一些内容(摘录来自网络)。

  • 相关阅读:
    IDEA快捷方式
    JVM调优总结
    log4g详细配置
    大前端完整学习路线(详解)
    Tomcat工作原理
    Oracle
    Servlet知识
    lmap
    常见博客API
    PL/SQL入门理解(一)
  • 原文地址:https://www.cnblogs.com/insus/p/4317185.html
Copyright © 2011-2022 走看看