js進階 11-6 jquery如何獲取和設置元素的寬高(jquery多方法)

js進階 11-6? jquery如何獲取和設置元素的寬高(jquery多方法)

一、總結

一句話總結:jquery里面多是方法啊,比如jquery對象的寬高。所以取值是方法,賦值就是方法里面帶參數。

?

1、百度富文本編輯器ueditor如何設置寬高?

jquery對象的width()和height()方法

37             $('#btn2').click(function(){ 38  $("#div1").width(50) 39  $('#div1').height(50) 40  })

?

2、juqery對象的寬高對應的三個方法是什么,分別表示什么意思?

元素的寬度高度

  1. width() 方法設置或返回元素的寬度(不包括內邊距、邊框或外邊距)。
  2. innerWidth() 方法返回元素的寬度(包括內邊距)
  3. outerWidth() 方法返回元素的寬度(包括內邊距和邊框)
  4. height()、innerHeight()、outerHeight()與寬度類似

?

3、juqery對象如何設置一個表示全副武裝的寬度(包括相關的一切)?

outerWidth()方法加true參數

34             //outerWidth()    width + padding + border+margin
35                 alert($("#div1").outerWidth(true))

?

4、juqery對象的innerWidth()方法包括的是哪個邊距?

內邊距? padding

?

5、jquery的匿名函數中的index參數表示什么意思?

因為jquery對象多是集合,所以index就是表示所選元素的下標

43                 $("#main div").width(function(index,oldWidth){ 44 //alert(index) 45 return oldWidth*(index+1)/5 46  })

?

?

二、jquery如何獲取和設置元素的寬高

1、相關知識

元素的寬度高度

  1. width() 方法設置或返回元素的寬度(不包括內邊距、邊框或外邊距)。
  2. innerWidth() 方法返回元素的寬度(包括內邊距)
  3. outerWidth() 方法返回元素的寬度(包括內邊距和邊框)
  4. height()、innerHeight()、outerHeight()與寬度類似

?

?

2、代碼

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <style>
 4 </style>
 5 <head>
 6     <meta charset="UTF-8">
 7     <title>演示文檔</title>
 8     <script type="text/javascript" src="jquery-3.1.1.min.js"></script>
 9     <style>
10         #main{
11             background: #ccc;padding: 10px;float: left;
12         }
13         #div1,#div2,#div3{background: red;padding: 10px;margin:10px;width: 200px;height: 200px;border:solid 3px green;}
14     </style>
15 </style>
16 </head>
17 <body>
18     <div id="main">
19         <div id="div1"></div>
20         <div id="div2"></div>
21         <div id="div3"></div>
22     </div>
23     <input id="btn1" type="button" value="獲取">
24     <input id="btn2" type="button" value="設置">    
25     <input id="btn3" type="button" value="設置2">
26     <script type="text/javascript">
27         $(function(){
28             $('#btn1').click(function(){
29                 alert($("#div1").width())
30                 //width + padding
31                 alert($("#div1").innerWidth())
32                 //outerWidth()    width + padding + border
33                 alert($("#div1").outerWidth())
34             //outerWidth()    width + padding + border+margin
35                 alert($("#div1").outerWidth(true))
36             })
37             $('#btn2').click(function(){
38                 $("#div1").width(50)
39                 $('#div1').height(50)
40             })
41             
42             $('#btn3').click(function(){
43                 $("#main div").width(function(index,oldWidth){
44                     //alert(index)
45                     return oldWidth*(index+1)/5
46                 })
47             })
48         })
49     </script>
50 </body>
51 </html>

?

?

?

?

?

?

?

?

?

轉載于:https://www.cnblogs.com/Renyi-Fan/p/9202160.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/280086.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/280086.shtml
英文地址,請注明出處:http://en.pswp.cn/news/280086.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

SparseArray代替HashMap

相信大家都明白&#xff0c;手機軟件的開發不同于PC軟件的開發&#xff0c;因為手機性能相對有限&#xff0c;內存也有限&#xff0c;所謂“寸土寸金”&#xff0c;可能稍有不慎&#xff0c;就會導致性能的明顯降低。Android為了方便開發者&#xff0c;特意在android.util這個包…

也許你曾經讀過他的書

我們愿用“能理能文、才華多元”來形容他。因為熱愛編程和游戲&#xff0c;所以他將愛好變成了職業&#xff0c;并在這條路上持續奔跑&#xff1b;因為熱愛分享&#xff0c;所以他堅持在博客上分享技術觀點并出版了關于 Azure、微軟游戲棧的書籍&#xff1b;因為熱愛挑戰&#…

python測試框架數據生成工具最全資源匯總

xUnit frameworks 單元測試框架frameworks 框架unittest - python自帶的單元測試庫&#xff0c;開箱即用unittest2 - 加強版的單元測試框架&#xff0c;適用于Python 2.7以及后續版本pytest - 成熟且功能強大的單元測試框架plugincompat - pytest的執行及兼容性插件nosetests -…

t30智能插座怎么設置_如何設置ConnectSense智能插座

t30智能插座怎么設置If you like the idea of smart outlets, but wish you had one with more than just one receptacle on it, the ConnectSense Smart Outlet is worth looking into. Here’s how to set it up and instantly get double the fun. 如果您喜歡智能插座的想法…

用鏈表和數組實現HASH表,幾種碰撞沖突解決方法

Hash算法中要解決一個碰撞沖突的辦法&#xff0c;后文中描述了幾種解決方法。下面代碼中用的是鏈式地址法&#xff0c;就是用鏈表和數組實現HASH表。 he/*hash table max size*/ #define HASH_TABLE_MAX_SIZE 40/*hash table大小*/ int hash_table_size0;/*.BH----------------…

安卓操作sqlite3,增刪改查

創建 layout <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"android:orientation"vertical"android:layout_width"match_parent"android:layo…

基于.NetCore開發博客項目 StarBlog - (23) 文章列表接口分頁、過濾、搜索、排序

1前言上一篇留的坑&#xff0c;火速補上。在之前的第6篇中&#xff0c;已經有初步介紹&#xff0c;本文做一些補充&#xff0c;已經搞定這部分的同學可以快速跳過&#xff0c;基于.NetCore開發博客項目 StarBlog - (6) 頁面開發之博客文章列表對標準的WebApi來說&#xff0c;分…

如何在Chrome中保存您當前的所有標簽,以便以后閱讀

Chrome allows you to open tabs from your last browsing session when you open the browser. However, what if you want to save your current set of tabs to re-open at any time? Chrome doesn’t provide a way to do that natively, but there is an easy workaround…

ubuntu 16.04(Windows 10雙系統+grub引導)無法進入tt1~tt6(NVIDIA驅動安裝相關-黑屏,login loop,分辨率)...

目錄 前言回顧最終解決&#xff1a;0.關閉x服務1.禁用nouveau2.加入3.更新4.查找匹配驅動5.選擇推薦版本6.等待安裝后重啟,nvidia-smi查看是否安裝成功,或者lsmod | grep nvidia&#xff0c;成功結果如下7.重啟x服務8.此時還不能進入圖形界面&#xff0c;因為nomodeset還在&…

(備忘)打開office2010總是在配置進度

1、同時按上鍵盤上面的windows鍵和R鍵&#xff0c;出現“運行” 2、輸入“regedit”&#xff0c;回車進入注冊表 3、點擊“HKEY_CURRENT_USER”展開&#xff0c;依次“Software”--“Microsoft”--“Office”--"14.0"--"Word"展開&#xff0c;點擊"Op…

java、oracle對CLOB處理

oracle CLOB字段轉換位VARCHAR 1.實際上處理CLOB字段的時候&#xff0c;直接TO_CHAR&#xff0c;當長度超過4000的時候&#xff0c;會報錯&#xff0c;提示列被截取&#xff1b; CLOB轉varchar2&#xff1a;select to_char(CLOB字段) from table 2.直接使用SUBSTR對CLOB字段進行…

android 更改軟鍵盤_如何在Android的Google鍵盤上更改聲音和振動

android 更改軟鍵盤Tactile feedback from a touch screen keyboard is crucial, in my opinion, but I don’t like sounds when I tap keys. You may not be like me—maybe sounds are your thing, but vibration is annoying. Or maybe you dislike both (you rebel!). The…

『 再看.NET7』看看required屬性有什么不同

還是先看看C#中屬性的這定義&#xff0c;在初始化和訪問上有哪些方式&#xff0c;就能看出required屬性有什么不一樣的地方了。屬性&#xff0c;是封裝字段的&#xff0c;通過get和set訪問器可以很好地驗證數據的有效性。public record Order_00 {public Guid Id { get; set; }…

知識點:Mysql 索引原理完全手冊(1)

知識點&#xff1a;Mysql 索引原理完全手冊(1) 知識點&#xff1a;Mysql 索引原理完全手冊(2) 知識點&#xff1a;Mysql 索引優化實戰(3) 知識點&#xff1a;Mysql 數據庫索引優化實戰(4) Mysql-索引原理完全手冊 一、 介紹二、 索引的原理三、 索引的數據結構四、 聚集索引與輔…

如何將Apple Mail建議用于事件和聯系人

Apple products come preinstalled with an email client that can, on occasion, be quite smart. Today we want to show you another great feature: suggestions for event and contacts. Apple產品預裝了一個電子郵件客戶端&#xff0c;該客戶端有時可能非常聰明。 今天&a…

TPshop表結構

tp_account_log -- 賬戶表 字段名字段類型默認值描述log_idmediumint(8) unsigned 日志iduser_idmediumint(8) unsigned 用戶iduser_moneydecimal(10,2)0.00用戶金額frozen_moneydecimal(10,2)0.00凍結金額pay_pointsmediumint(9) 支付積分change_timeint(10) unsigned 變動時間…

Redis 通配符批量刪除key

問題&#xff1a; 線上有部分的redis key需要清理。 一、 由于Keys模糊匹配&#xff0c;請大家在實際運用的時候忽略掉。因為Keys會引發Redis鎖&#xff0c;并且增加Redis的CPU占用&#xff0c;情況是很惡劣的&#xff0c; 官網說明如下&#xff1a; Warning: consider KEYS as…

如何在 .Net 7 中將 Query 綁定到數組

在 .Net 7 中&#xff0c;我們可以通過綁定數組的方式來接收來自查詢字符串的參數。這樣就不需要再使用逗號分隔的字符串來獲取參數了。代碼演示 假設我們需要從 query 上接受多個 id 并返回查詢的結果。例如&#xff1a;id1&id2在 .Net 7 中&#xff0c;我們可以這樣實現&…

xbox one 越獄_如何在Xbox One上播放視頻和音樂文件

xbox one 越獄The Xbox One has integrated TV features and support for streaming media apps like Netflix and Hulu, but that isn’t where it ends. You can play video and music files you’ve ripped or downloaded by plugging in a USB drive or streaming them ove…

C++實驗七

11——3 #include<fstream>using namespace std;int main(){ ofstream file; file.open("test1.txt",ios_base::binary); file<<"已成功添加字符&#xff01;"; file.close(); return 0; } 11-4 #include<fstream>#include<iostrea…