在jQuery中更改div的字体大小 [英] changing font size of div in jQuery
问题描述
如果我使用iphone,我想用jquery更改字体大小.我从
开头的样式部分开始txtArea {font-size:30px}
我体内有以下代码 if($(window).width()< 600){$('#txtArea').css('font-size','60px');}
但是,在iPhone上,文本很小.知道是什么原因造成的吗?谢谢.
如果将<script>
元素放在#txtArea
元素之前,则代码将找不到该元素---因此将不执行任何操作. /p>
您应将代码包装在准备好文档的处理程序中,如下所示:
<script>
$(document).ready(function() {
if ($(window).width() < 600) {
$('#txtArea').css('font-size', '60px');
}
});
</script>
然后,直到#txtArea
元素存在之后,代码才会执行.
I want to change the font size with jquery if I'm using an iphone. I start in the style section in the head with
txtArea {font-size:30px}
I have the following code in the body if ($(window).width() < 600) { $('#txtArea').css('font-size', '60px');}
However, on the iphone the text stays small. Any idea what could cause this? Thanks.
If you placed your <script>
element before the #txtArea
element, the code will not find the element --- and therefore will not do anything.
You should wrap your code in a document ready handler like this:
<script>
$(document).ready(function() {
if ($(window).width() < 600) {
$('#txtArea').css('font-size', '60px');
}
});
</script>
Then the code will not execute until after the #txtArea
element exists.
这篇关于在jQuery中更改div的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!