如何将这个js函数应用于输入标记并返回结果。以下是javascript函数:
function checkFocus() {
if ($(document.activeElement).attr("type") == "text" || $(document.activeElement).attr("type") == "textarea") {
//Something's selected
return true;
}以下是html:
<input type="text" name="fname"value="">我的目的是检查输入框是否被选中。
发布于 2020-04-22 07:44:50
假设您正在使用jQuery (因为您的代码中有$(document.activeElement) ),您可以使用focus监听器,如下所示:
$("input[type=text], input[type=textarea]").focus(() => {
// Do something with the element
});这将触发每次您选择一个输入框(焦点)。查看用于jQuery的焦点事件侦听器文档
https://stackoverflow.com/questions/61359683
复制相似问题