使用javascript的字体大小调整器不起作用

问题描述 投票:1回答:2

我正在尝试为用户创建字体大小调整器。我可以使用“这个”来做框。但是我不能用按钮。我怎么能这样做?我正在使用class not id(如果我使用#keko那么它的工作)

.keko {
    position: relative;
    width:70px;
	height:70px;
    margin: auto;
	font-size: 15px;
    background: green;
    }
<link rel="stylesheet" href="Label.css%20-%20Label%20every%20thing!_dosyalar/style.css">
<link rel="stylesheet" href="Label.css%20-%20Label%20every%20thing!_dosyalar/label.css">
     
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $(".keko").click(function(){
            $(this).css("font-size", "50px");
        });    
    });	
    </script>
                  
 <div class="keko"><p>This text</p><div>
 <button type="button">Add CSS Styles</button>
javascript css
2个回答
2
投票

使用相应的选择器:

$(document).ready(function() {
  $('button').click(function() {
    $(".keko").css("font-size", "50px");
  });
});
.keko {
  position: relative;
  width: 70px;
  height: 70px;
  margin: auto;
  font-size: 15px;
  background: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<div class="keko">
  <p>This text</p>
<div>

<button type="button">Add CSS Styles</button>

2
投票

只要我关闭head标签,这对我有用。

<!DOCTYPE html>
<html lang="en">
<head>
<style>
    .keko {
        position: relative;
        width:70px;
        height:70px;
        margin: auto;
        font-size: 15px;
        background: green;
    }
</style>
</head>
<body>
    <script src="http://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".keko").click(function(){
                $(this).css("font-size", "50px");
            });    
        }); 
    </script>

    <div class="keko"><p>This text</p><div>
    <button type="button">Add CSS Styles</button>

</body>
</html>

© www.soinside.com 2019 - 2024. All rights reserved.