zoukankan      html  css  js  c++  java
  • jquery属性操作

    属性操作

    1.属性
    设置单选框被选中:
    $(document).ready(function(){
    $(":checkbox").attr("checked","true");
    });
    取消选中:
    $(document).ready(function(){
    $(":checkbox").removeAttr("checked");
    });
    禁用和选中所有页面上的复选框:
    $(document).ready(function(){
    $("input[type='checkbox']").prop("disabled", false);
    $("input[type='checkbox']").prop("checked", true);
    });
    移除用prop选中的单选框:
    $(document).ready(function(){
    $("input[type='checkbox']").removeProp("checked");
    });
    <body>
    <div>test1</div>
    <div id="d" >test2</div>
    <input type="button" value="Input Button"/>
    <input type="checkbox" />
    <input type="password" />
    <input type="radio" />
    <input type="reset" />
    <input type="text" value="文本框" />
    <input type="submit" />
    </body>

    2.css类
    为p元素添加类名:
    $(document).ready(function(){
    $("p").addClass("selected");
    });
    删除p元素的类名:
    $(document).ready(function(){
    $("p").removeClass("selected");
    });
    如果存在(不存在)就删除(添加)一个类
    $("p").toggleClass("selected");

    <body>
    <p>p</p>
    </body>

    3.html属性 (html,text,val)

    html返回p元素内容:
    $(document).ready(function(){
    var n= $("p").html();
    alert(n);
    });
    html设置p元素内容(标签有效):
    $(document).ready(function(){
    $("p").html("hello <b>world</b>");
    });
    text返回p元素内容:
    $(document).ready(function(){
    var p= $("p").text();
    alert(p);
    });
    text设置p元素内容(只是纯文本):
    $(document).ready(function(){
    $("p").text("Hello world!");
    });
    val设置input的值:
    $(document).ready(function(){
    $("input").val("hello world!");
    });

    <body>
    <input type="text" value="文本框" />
    <p>p</p>
    </body>

  • 相关阅读:
    Java HttpClient使用小结
    【剑指offer】Q18:树的子结构
    poj3041-Asteroids , 二分图的最小顶点覆盖数 = 最大匹配数
    jquery.validate+jquery.form提交的三种方式
    &quot;undefined reference to&quot; 问题解决方法
    [Oracle]
    Effective_java之二:慎用重载函数
    C99规范
    迭代、递归替代循环
    1)Linux程序设计入门--基础知识
  • 原文地址:https://www.cnblogs.com/qinyi173/p/4951362.html
Copyright © 2011-2022 走看看