Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 聚焦于div_Javascript_Html_Css - Fatal编程技术网

Javascript 聚焦于div

Javascript 聚焦于div,javascript,html,css,Javascript,Html,Css,下午好。告诉我如何禁用翻译本身的元素焦点?通过单击div,它不应该转换自己的焦点。谢谢你 https://jsfiddle"dot"net/ironviper/boyorkdy/ 如果您在此处的“我的文本”中单击鼠标,然后单击“确认我是”按钮,则焦点将保留在此处的“我的文本”字段中。 如果你在我的文本中单击鼠标,然后单击CLECK ME i m div,焦点将离开我的文本字段。 当您单击“确认我我是div”时,如何禁用“我的文本”字段的焦点?您可以将焦点bact设置为可编辑的div。 我从中找

下午好。告诉我如何禁用翻译本身的元素焦点?通过单击div,它不应该转换自己的焦点。谢谢你

https://jsfiddle"dot"net/ironviper/boyorkdy/
如果您在此处的“我的文本”中单击鼠标,然后单击“确认我是”按钮,则焦点将保留在此处的“我的文本”字段中。 如果你在我的文本中单击鼠标,然后单击CLECK ME i m div,焦点将离开我的文本字段。
当您单击“确认我我是div”时,如何禁用“我的文本”字段的焦点?

您可以将焦点bact设置为可编辑的div。 我从中找到了“setEndOfContenteditable”函数


请提供该问题的演示你在说什么?编辑您的帖子并添加一些您已经试用过的代码。我们不能联系太多
<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <div id="editId" contenteditable="true">My text here</div>
    <div id="myDiv" onclick="myclick();">CLICK ME i'm div</div>
</body>
<script>
    function myclick() {
        var el = document.getElementById("editId");
        el.focus();
        setEndOfContenteditable(el);
    }

    function setEndOfContenteditable(contentEditableElement) {
        var range, selection;
        if (document.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
        {
            range = document.createRange();//Create a range (a range is a like the selection but invisible)
            range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range
            range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
            selection = window.getSelection();//get the selection object (allows you to change selection)
            selection.removeAllRanges();//remove any selections already made
            selection.addRange(range);//make the range you have just created the visible selection
        }
        else if (document.selection)//IE 8 and lower
        {
            range = document.body.createTextRange();//Create a range (a range is a like the selection but invisible)
            range.moveToElementText(contentEditableElement);//Select the entire contents of the element with the range
            range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start
            range.select();//Select the range (make it the visible selection
        }
    }
</script>
</html>