jQuery的 - 减少标题的大小
问题描述:
我想通过一个jQuery的 - 减少标题的大小
例子来降低我的网页上的所有标题:
<h1>Hi</h1> -> <h2>Hi</h2> <h3>Moin</h3> -> <h4>Hi</h4>
什么是实现这一目标的jQuery的最佳方法是什么?
谢谢!
答
可能并非最好的解决办法,但你可以试试这个:
$("h1, h2, h3, h4, h5").each(function() {
if($(this).is("h1")) {
$(this).replaceWith("<h2>" + $(this).text() + "</h2>");
}
else if($(this).is("h2")){
$(this).replaceWith("<h3>" + $(this).text() + "</h3>");
}
else if($(this).is("h3")){
$(this).replaceWith("<h4>" + $(this).text() + "</h4>");
}
else if($(this).is("h4")){
$(this).replaceWith("<h5>" + $(this).text() + "</h5>");
}
else if($(this).is("h5")){
$(this).replaceWith("<h6>" + $(this).text() + "</h6>");
}
});
任何从你身边的尝试? –
你可以添加更多信息你需要什么?如果你想增加或减少字体大小。尝试在这里:http://*.com/questions/24241457/increasing-decreasing-font-size-on-button-click –
其实我想为类自定义类做一些事情,但意识到使用属性它更容易:让headIndex = parseInt($(this).attr(“data-head-index”))|| 0; 尽管如此,我仍然认为最初的问题可能会让人感兴趣。 – Gustav