我正在尝试为以“drop_”开头的所有元素设置Jquery“line-height”css值。当我运行相同的代码将“line-height”替换为“font-size”时,它会正确更新,但无法获得“line-height”更新。任何想法??
$.each($('[id^=drop_]'), function(index, value) {
alert($(this).css("line-height"));
$(this).css("line-height", "3.5px");
alert($(this).css("line-height"));
});
答案 0 :(得分:1)
对于line-height
属性值,
试试这个,
$.each($('[id^=drop_]'), function(index, value) {
alert($(this).css("line-height"));
$(this).css("line-height", "3.5");
alert($(this).css("line-height"));
});
注意:强> 当我们将值作为无单位数提供时,将乘以元素的font-size来计算行框高度。
答案 1 :(得分:1)
试试这个
jQuery.each(jQuery('[id^=drop_]'), function(index, value) {
alert(jQuery(this).css("line-height"));
jQuery(this).css("line-height", "35px");
alert(jQuery(this).css("line-height"));
});

p { line-hieght: 10px; }

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="drop_first">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p id="drop_second">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p id="drop_third">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p id="drop_fourth">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<p id="drop_fifth">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
&#13;
答案 2 :(得分:0)
$('.div > p').css('line-height', '3.5px');
请发布您的HTML。或者相应地更改.div > p
部分。这应该可以正常工作。
你拥有的,对我来说也很好。如果它不适合您,请尝试使用我的代码更新它。