每次按下按钮时减小字体大小的 jquery 函数

Jos*_*son 3 html css jquery

请帮忙。

function fontDown() {
  var curSize = parseInt($('.box').css('font-size'));
  curSize--;
  $('.box').css('font-size', curSize + "pt").css('line-height', curSize + "pt");
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button onclick="fontDown()">button</button>
    
<div class="box" style="font-size: 14pt; line-height: 14pt;">sometext</div>
Run Code Online (Sandbox Code Playgroud)

我希望每次按下按钮时字体大小都会减小。但是,它只会增加。不仅如此,每次按下按钮,字体大小都会增加大约 5 或 7 磅。

Tac*_*hin 5

使用这个:很容易

jquery 中应该使用 运算符+=, *=, -=,/=

function fontDown() {
  $('.box')
    .css('font-size', '-=1pt')
    .css('line-height', '-=1pt');
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button onclick="fontDown()">button</button>
    
<div class="box" style="font-size: 14pt; line-height: 14pt;">sometext</div>
Run Code Online (Sandbox Code Playgroud)