javascript – jQuery .text()显示双文本

一个奇怪的情况发生.我有一个< h3>里面有文字.当我用.text()提取此文本,然后将其放入< textarea>该文本出现两次.

Here is jsFiddle.

HTML

<h3 class="profileRightAboutMeText">heya,this is all the text.</h3>     
<textarea class="profileRightAboutMeTextarea"></textarea>

JQUERY

$(document).on('click','h6.editMyProfileSection',function() {
  var originalText = $('h3.profileRightAboutMeText').text();

  $('h3.profileRightAboutMeText').fadeOut('fast',function() {
    $('textarea.profileRightAboutMeTextarea').text(originalText).fadeIn('fast');
  });
  alert(originalText);
});

警报和< textarea>显示文字双重如下:

heya,这是所有的文字.heya,这是所有的文字.

解决方法

我会说你有2个元素匹配$(‘h3.profileRightAboutMeText’)在页面上.

您可以在这里看到:http://jsfiddle.net/KwcGB/,文本出现两次,因为我向html添加一个额外的h3.profileRightAboutMeText,但是如果额外的行被删除,那么它只会出现一次.

尝试将$(‘h3.profileRightAboutMeText’)放入firebug的控制台,并查看它匹配的元素数量

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...