【问题标题】:Find Line numbers of content in a Div jQuery [duplicate]在Div jQuery中查找内容的行号[重复]
【发布时间】:2015-07-22 05:52:25
【问题描述】:
$(document).ready(function() {
    var divheight = $("div").height(); 
    var lineheight = $("div").css('line-height').replace("px","");
    alert(Math.round(divheight/parseInt(lineheight)));
});

我试图在一个 div 中查找某些内容的行数。 div 高度将被固定。怎么解决?这请帮忙。 https://jsfiddle.net/id10922606/n94u3Lb2/1/

【问题讨论】:

  • jsfiddle.net/tusharj/n94u3Lb2/2 在包含 jQuery 后工作正常
  • @anoop 您没有在 fiddle 中选择 Jquery 框架扩展。因此,您的代码不起作用。检查控制台。它的捐赠 $ 没有定义。你的代码是正确的。只需从左侧下拉列表中选择 Jquery 框架。

标签: jquery


【解决方案1】:

这里是获取潜水内容行号的演示:

http://jsfiddle.net/brunoscopelliti/EPms9/

$(document).ready(function() {
  	var divheight = $("#startegy-sections-targeting-exclude").height(); 
	var lineheight = $("#startegy-sections-targeting-exclude").css('line-height').replace("px","");
	alert(Math.round(divheight/parseInt(lineheight)));
});
#startegy-sections-targeting-exclude {
	line-height:20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="startegy-sections-targeting-exclude">
  Something strange... <br/>maybe it's fault of the measure unit<br/>PX!
</div>

【讨论】:

  • 如果 Div 高度是固定的,那么如何获得行数?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-30
  • 1970-01-01
  • 2014-11-04
  • 2012-10-09
  • 1970-01-01
  • 2017-04-19
相关资源
最近更新 更多