jQuery 中的 Height方法函数

首页 / jQuery入门教程 / jQuery 中的 Height方法函数

Height()方法获取第一个匹配元素的当前计算输出、像素和高度。

Height - 语法

selector.height( )

此方法能够找到窗口和文档的高度,如下所示-

$(window).height();   //returns height of browser viewport
$(document).height(); //returns height of HTML document

Height - 示例

下面是一个简单的示例,一个简单的示例显示了这个方法-的用法

无涯教程网

<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>

这将产生以下输出-

链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/css-height.html

来源:LearnFk无涯教程网

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

小马哥讲Spring核心编程思想 -〔小马哥〕

接口测试入门课 -〔陈磊〕

etcd实战课 -〔唐聪〕

技术面试官识人手册 -〔熊燚(四火)〕

React Hooks 核心原理与实战 -〔王沛〕

说透5G -〔杨四昌〕

Spring Cloud 微服务项目实战 -〔姚秋辰(姚半仙)〕

Go进阶 · 分布式爬虫实战 -〔郑建勋〕

超级访谈:对话道哥 -〔吴翰清(道哥)〕

好记忆不如烂笔头。留下您的足迹吧 :)