简体   繁体   English

当应用javascript时,contenteditable = true停止工作

[英]contenteditable = true stops working when javascript is applied

Hi i have a text box that was working fine when i implemented contenteditable it was working. 嗨,我有一个文本框,当我实现contenteditable它工作正常。 But when i implemented jquery and javascript the contenteditable completely stopped working. 但是当我实现jquery和javascriptcontenteditable完全停止工作。 I don't know if this is normal or not, any help would be greatly appreciated. 我不知道这是否正常,将不胜感激。

HTML 的HTML

<!DOCTYPE HTML>
<html>

<head>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script type="text/javascript">
        $(function() {
            $(".note").resizable();
            $(".note").draggable();
        });
    </script>
    <title>Stickynote</title>
    <img src="images/logo.png">

</head>

<body>
    <div class="note" contenteditable="true">

    </div>
</body>

</html>

CSS 的CSS

body {
    background-image: url("images/background.jpg");
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

html {
    height: 100%;
}

html img {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.note {
    width: 300px;
    height: 300px;
    background-image: url("images/stickynote.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    padding: 10px;
}

.draggable() is preventing editable behavior. .draggable()阻止可编辑的行为。 You can fix this like below: 您可以按以下方式解决此问题:

$.fn.makeEditable = function () {
    return this.each(function () {
        $(this).on('cilck mousedown', function () {
            $(this).focus();
        });
    });
};

$('.note').draggable().resizable().makeEditable();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM