space_Home 2018-12-20 11:41 采纳率: 50%
浏览 453

这段代码中的this是指的什么值,求大神指导一下(JS中的this问题)

$('div.label').click(function() {
var paraWidth = $('div.speech p').outerWidth();
var $switcher = $(this).parent();
alter(paraWidth);
alter($switcher);
var switcherWidth = $switcher.outerWidth();
$switcher.animate({
borderWidth: '5px',
left: paraWidth - switcherWidth,
height: '+=20px'
}, 'slow');
});

<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8">
      <title>Abraham Lincoln's Gettysburg Address</title>

    <link rel="stylesheet" href="04.css" type="text/css" />

    <script src="jquery.js"></script>
    <script src="4.16.js"></script>
  </head>
  <body>
    <div id="container">
      <h2>Abraham Lincoln's Gettysburg Address</h2>
      <div id="switcher">
        <div class="label">Text Size</div>
        <button id="switcher-default">Default</button>
        <button id="switcher-large">Bigger</button>
        <button id="switcher-small">Smaller</button>
      </div>
      <div class="speech">
        <p>Fourscore and seven years ago our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated to the proposition that all men are created equal.</p>
        <p>Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field as a final resting-place for those who here gave their lives that the nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we cannot dedicate, we cannot consecrate, we cannot hallow, this ground.</p>
        <a href="#" class="more">read more</a>
        <p>The brave men, living and dead, who struggled here have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember, what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced.</p>
        <p>It is rather for us to be here dedicated to the great task remaining before us&mdash;that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion&mdash;that we here highly resolve that these dead shall not have died in vain&mdash;that this nation, under God, shall have a new birth of freedom and that government of the people, by the people, for the people, shall not perish from the earth.</p>
      </div>
    </div>
  </body>
</html>

  • 写回答

2条回答 默认 最新

  • Go 旅城通票 2018-12-20 03:43
    关注

    自己好好看下jquery的api,this为当前点击的label对象(DOM),不是jquery对象

    alter错了,这个是数据库的,js提示用alert

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line