在编辑文本框时,用于向文本框添加文本的jQuery脚本会中断

时间:2016-09-09 14:02:40

标签: jquery

我写了一个小脚本,当你点击它们时会在文本框中添加文本块,并且它有效。但是,如果在文本框中编辑某些内容,例如删除一个字符,则该脚本将不再有效。我必须刷新页面。这是代码:



$('#add-spec,#add-spec2,#add-spec3').click(function() {
  var currentVal = $('#current-content').html();
  var newVal = currentVal + '\n' + $(this).text();
  $('#current-content').html(newVal);
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<textarea id=current-content>Some current content</textarea>

<button id=add-spec>This is something to add</button>
<button id=add-spec2>My name is Eniego Montoya</button>
<button id=add-spec3>There's a snake in my boot</button>
&#13;
&#13;
&#13;

有什么想法吗?

0 个答案:

没有答案