在jQuery中更改div的字体大小 [英] changing font size of div in jQuery

查看:273
本文介绍了在jQuery中更改div的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆