亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery中width()方法用法實例

 更新時間:2014年12月24日 14:20:44   投稿:shichen2014  
這篇文章主要介紹了jQuery中width()方法用法,以實例形式較為詳細的分析了width()方法獲取元素寬度的技巧,具有一定的參考借鑒價值,需要的朋友可以參考下

本文實例講述了jQuery中width()方法用法。分享給大家供大家參考。具體分析如下:

此方法可以獲取或者設置匹配元素的寬度值,默認單位是px。

語法結構一:

復制代碼 代碼如下:
$(selector).width()

不帶參數(shù)的時候是返回第一個匹配元素的當前寬度。
實例代碼:

復制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://chabaoo.cn/" />
<title>腳本之家</title>
<style type="text/css">
div{
  height:150px;
  width:150px;
  background-color:green;
  margin-top:10px;
  text-align:center;
  line-height:150px;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("div").text($("div").width())
})
</script>
</head>
<body>
  <div></div>
</body>
</html>

語法結構二:

復制代碼 代碼如下:
$(selector).width(val)

帶參數(shù)的時候是設置所有匹配元素的寬度,默認單位是px,當然也可以使用其他的單位如em或者百分比等等。
實例代碼:

復制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://chabaoo.cn/" />
<title>CSS教程</title>
<style type="text/css">
span{
  color:red;
}
</style>
<title>腳本之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#btn").click(function(){
    alert($("li").index());
  })
});
</script>
</head>
<body>
<div>
  <ul>
    <li>后臺專區(qū)</li>
    <li>前臺專區(qū)</li>
    <li>數(shù)據(jù)庫專區(qū)</li>
    <li>站長交流</li>
  </ul>
</div>
<div>當前l(fā)i元素的位置:<span>0</span></div>
<button id="btn">點擊查看實例</button>
</body>
</html>

希望本文所述對大家的jQuery程序設計有所幫助。

相關文章

最新評論