zoukankan      html  css  js  c++  java
  • jQuery设计思想之取值和赋值

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
    <script>
    $(function(){
        //js写法 有参数的是赋值,没有参数的是取值
    var oDiv=document.getElementById('div1');
        oDiv.innerHTML = 'hello';  //赋值    
        alert( oDiv.innerHTML );  //取值
        //jquery的写法  有参数的是赋值,没有参数的是取值
        $('#div1').html('hello');  //赋值    
        alert( $('#div1').html() ); //取值
    
        css('width','200px')//两个参数是设置
        css('width')//一个参数是获取
    });
    </script>
    </head>
    <body>
    <div id="div1">div</div>
    </body>
    </html>
    <ul>
        <li>aaa</li>
        <li>bbb</li>
        <li>ccc</li>
        <li>ddd</li>
    </ul>
    $(function(){
        alert( $('li').html() );  //当一组元素的时候,取值是一组中的第一个,若想取所有用循环
        $('li').html('hello');  //当一组元素的时候,赋值是一组中的所有元素    
    });
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="jquery-1.10.1.min.js"></script>
    <script>
    $(function(){
        //attr 属性
        alert($('div').attr('title'));//弹出123,取值    
        $('div').attr('title','456');//鼠标移上去是456       设置
        $('div').attr('class','box');//审查元素class="box"  设置
        
    });
    </script>
    </head>
    <body>
    <div title="123">div</div>
    </body>
    </html>
  • 相关阅读:
    378. Kth Smallest Element in a Sorted Matrix
    372. Super Pow
    357. Count Numbers with Unique Digits
    345. Reverse Vowels of a String
    343. Integer Break
    347. Top K Frequent Elements
    344. Reverse String
    338. Counting Bits
    326. Power of Three
    python练习
  • 原文地址:https://www.cnblogs.com/Xuman0927/p/5611570.html
Copyright © 2011-2022 走看看