gpt4 book ai didi

javascript - 检查何时选择/标记了一个元素

转载 作者:行者123 更新时间:2023-11-30 15:56:00 24 4
gpt4 key购买 nike

我有一个 HTML 页面,其中有一些带有 contenteditable="true"div。我还按顺序设置了 tabindex,这样当用户点击选项卡时,他或她将浏览所有可编辑的 div。但是,现在我在每个 div 中都写了“Insert notes here”(见下文)。

<div contenteditable="true" tabindex='1'>Insert notes here<div>
<div contenteditable="true" tabindex='2'>Insert notes here<div>
<div contenteditable="true" tabindex='3'>Insert notes here<div>

当用户切换到 div 时,我试图摆脱“Insert notes here”文本。现在,如果他们使用以下 jQuery 单击文本,我就可以删除文本:

function selectText(containerid) {
if(document.getElementById(containerid).innerHTML == "Insert notes here") {
document.getElementById(containerid).innerHTML = "";
}
}

有没有办法在用户使用 tab 时也能达到同样的效果?

最佳答案

听起来你正在寻找 onfocus 事件

http://www.w3schools.com/jsref/event_onfocus.asp

在 jquery 中:

$("#fieldId").focus(function() {
//your code here
});

关于javascript - 检查何时选择/标记了一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38533492/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com