简体   繁体   English

jQuery:更改字体大小不起作用

[英]JQuery: changing font-size not working

I am following a tutorial at thenewboston.com: I have copied exactly as the tutorial has given: his works but not mine: where is the error? 我正在thenewboston.com上关注一个教程:我已完全按照该教程的说明进行了复制:他的作品而不是我的作品:错误在哪里? The alert(current) should return the current font size: nothing works despite I have followed the tutorial precisely semicolon for semicolon and comma for comma. alert(current)应该返回当前的字体大小:尽管我严格按照本教程进行了分号(对于分号)和逗号(对于逗号),但是仍然没有任何效果。 (I have repeatedly typed and retyped this according to the tutorial: it works in the tutorial but not for me. ) (我已经根据本教程反复键入并重新键入了它:它在本教程中有效,但不适用于我。)

Here is the html: 这是html:

  <!-- font size switcher-->
  Font size: <a href="#" id="smaller">Smaller</a>  <a href="#" id="bigger">Bigger</a>

 <p>This is some text</p>
  <p>This is some more text</p>

  <!--- script links --->  
  <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
  <script type="text/javascript" src="js/selectors_two.js"></script> 

Here is the code: 这是代码:

function change_size(element, size) {
    var currrent = element.css('font-size');
    // Check: alert() to return current font-size
    alert(current);

}
// derisive comment...
alert('Ha! You thought this would work!');

$('#smaller').click(function() {
change_size($('p'), 'smaller');
});

$('#bigger').click(function() {
change_size($('p'), 'bigger');
});

Even there is more coding following on at this stage of code all that is needed to happen is the alert(current). 即使在此阶段的代码后面有更多的编码,所有需要发生的就是警报(当前)。 And it doesn't. 事实并非如此。 Why? 为什么?

And yes, I know about the use of .on(): I even tried to recast using .on(). 是的,我知道.on()的用法:我什至尝试使用.on()重铸。

您有一个错字:用三个'r'声明为currentvar currrent

Replace your code with below code 用下面的代码替换您的代码

function change_size(element, size)
{
var current=element.css("font-size");
alert(current);
}

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

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