jQuery訪問屬性,絕對位置,jquery訪問屬性

來源:互聯網
上載者:User

jQuery訪問屬性,絕對位置,jquery訪問屬性

一. jQuery訪問屬性

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>jQuery attr demo</title></head><body><input id="check" type="checkbox" checked="checked"><label for="check">複選框</label><p></p></body><script type="text/javascript" src="jquery-2.1.1.min.js"></script><script type="text/javascript">$(function(){$("input").change(function(){var $input = $(this);$("p").html(".attr('checked') = <b>" + $input.attr('checked') + "</b><br>"   + ".prop('checked') = <b>" + $input.prop('checked') + "</b><br>"    + ".is(':checked') = <b>" + $input.is(':checked') );}).change();})</script><style>b {color: red;}</style></html>

二. jQuery絕對位置

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>jQuery absolute fix demo</title></head><body><div>盒子1</div><div style="float:left">盒子2</div><div style="float:left">盒子3</div></body><script type="text/javascript" src="jquery-2.1.1.min.js"></script><script type="text/javascript" >$(function(){    var o1 = $("div").eq(0).offset();//擷取第一個div元素的位移資訊    $("div").eq(0).html( "left: " + o1.left + "<br />top: " + o1.top ); //顯示資訊    var o2 = $("div").eq(1).offset();//擷取第二個div元素的位移資訊    $("div").eq(1).html( "left: " + o2.left + "<br />top: " + o2.top ); //顯示資訊    var o3 = $("div").eq(2).offset();//擷取第三個div元素的位移資訊    $("div").eq(2).html( "left: " + o3.left + "<br />top: " + o3.top ); //顯示資訊})</script><style type="text/css">body { padding:0; margin:0; }/*清除頁面邊界*/div {height:60px; width:200px; border:solid 10px red; }/*統一div元素的顯示樣式*/ </style></html>





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.