当鼠标不在里面时获取文本区域的值



我想这样做:

我有一个带有一些文本的文本区域,鼠标在文本区域中处于"打开"状态。当我从文本区域拿走鼠标时,我想获取以<span><p>编写的文本。

当鼠标不在文本区域中时,是否有获取信息的功能?

当你用jQuery标记问题时,我假设你有jQuery。然后,你可以做

$('textarea').mouseleave(function () {
  $('span').html($(this).val())
})

如果您的 HTML 看起来像

<textarea></textarea>
<span></span>

使用 jQuery,你可以采用 .mouseleave() 方法。

有关完整信息,请访问该函数的jQuery文档。

你在寻找这样的东西吗?

$(function () {
  $(".theArea").mouseover(function () {
    $(this).prop("contenteditable", true);
  }).mouseleave(function () {
    $(this).prop("contenteditable", false);
  });
});
.theArea {border: 1px solid #999; padding: 5px;}
.theArea[contenteditable="true"] {background: #ddf;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="theArea">Pages you view in incognito tabs won’t stick around in your browser’s history, cookie store, or search history after you’ve closed all of your incognito tabs. Any files you download or bookmarks you create will be kept.
However, you aren’t invisible. Going incognito doesn’t hide your browsing from your employer, your internet service provider, or the websites you visit.</div>

最新更新