无涯教程-jQuery - height( val )方法函数

height(val)方法设置每个匹配元素的CSS高度。

height( val ) - 语法

selector.height( val )

这是此方法使用的所有参数的描述-

  • val    -  这是元素的高度。如果未指定任何显式单位(如em或%),则将" px"连接到该值。

height( val ) - 示例

以下是一个简单的示例,简单说明了此方法的用法-

<html>
   <head>
      <title>The jQuery Example</title>
      <script type="text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type="text/javascript" language="javascript">
         $(document).ready(function() {
   
   
			
            $("div").click(function () {
   
   
               var color=$(this).css("background-color");
               var height=$(this).height();
               
               $("#result").html("That div is <span>" +color+ "</span>.");
               $("#result").css({
   
   color: color, background-color:gray});
               $("#result").height( height );
            });
				
         });
      </script>
		
      <style>
         div {
   
    width:60px; height:60px; margin:5px; float:left; }
      </style>
   </head>
	
   <body>
      <p>Click on any square:</p>
      <span id="result"> </span>
		
      <div style="background-color:blue; height:50px;"></div>
      <div style="background-color:pink;height:30px;"></div>
      <div style="background-color:#123456;height:100px;"></div>
      <div style="background-color:#f11; height:75px;"></div>
   </body>
</html>

这将产生以下输出-

jQuery 中的 height( val )方法函数 - 无涯教程网无涯教程网提供height(val)方法设置每个匹配元素的CSS高度。 height( val ) - 语法 selector . heigh...https://www.learnfk.com/jquery/css-height-val.html

猜你喜欢

转载自blog.csdn.net/w116858389/article/details/132021129
今日推荐