📜  jQuery |宽度()

📅  最后修改于: 2022-05-13 01:55:55.059000             🧑  作者: Mango

jQuery |宽度()

width()是 JavaScript 中的一个内置函数,用于检查元素的宽度。它不检查元素的内边距、边框和边距。
句法:

$("param").width()

参数:这里的参数是“param”,它是要提取宽度的元素的类或id。
返回值:它返回所选元素的宽度。

jQuery 代码来显示这个函数的工作:

代码#1:

  

    
    
    

  

    
         

Click on the button and check the width of the        element (excluding padding).

  

输出:
在点击按钮之前——

点击按钮后——

jQuery还包括innerWidth()方法,即,它还用于检查元素的内部宽度,包括填充。
句法:

$("param").innerWidth()

参数:这里的参数“param”是要提取宽度的元素的类或id。

返回值:返回被选元素的宽度。
代码#2:


  

    
    


  

    
         

Click on the button and check the innerWidth of         an element(includes padding).

  

在点击按钮之前——

点击按钮后——