简体   繁体   English

单击按钮无法增加字体大小

[英]Unable to increase font size on click of a button

I want to change the font size of two divs when I click on a particular button however button click is not responding, pls help. 我想在单击特定按钮时更改两个div的字体大小,但是按钮单击没有响应,请帮助。 I am using two div IDs in one selector. 我在一个选择器中使用了两个div ID。 also pls let me know where is the error, below is my code. 还请让我知道错误在哪里,下面是我的代码。

<html>

<head>
<title>
Example 2
</title>

<style>

    body
    {
        margin:10px 2em;
    }
    .switcher
    {
        float:right;
        margin:10px;
        background-color:#ddd;
        border: 1px solid #000;
        padding : 10px;
        font-size:0.9em;
    }

    .large
    {
        font-size:2em;
    }

</style>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
    $(document).ready(function{
        $('#switcher-large').on('click',function(){
            $('#header, #chapter-preface').addClass('large');
        });
    });
</script>
</head>

<body>
<div id="container">

      <div id="switcher" class="switcher">
        <h3>Style Switcher</h3>
        <button id="switcher-default">
          Default
        </button>
        <button id="switcher-narrow">
          Narrow Column
        </button>
        <button id="switcher-large">
          Large Print
        </button>
      </div>

      <div id="header">
        <h2>A Christmas Carol</h2>
        <h2 class="subtitle">In Prose, Being a Ghost Story of Christmas</h2>
        <div class="author">by Charles Dickens</div>
      </div>

      <div class="chapter" id="chapter-preface">
        <h3 class="chapter-title">Preface</h3>
        <p>I HAVE endeavoured in this Ghostly little book, to raise the Ghost of an Idea, which shall not put my readers out of humour with themselves, with each other, with the season, or with me.  May it haunt their houses pleasantly, and no one wish to lay it.</p>
        <p>Their faithful Friend and Servant,</p>
        <p>C. D.</p>
        <p>December, 1843.</p>
      </div>


</body>

</html>

You have a syntax error 您有语法错误

Try replacing 尝试更换

$(document).ready(function{

for 对于

$(document).ready(function(){

尝试这个

$('#header h2, #chapter-preface h3, #chapter-preface p').addClass('large');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM