首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当应用javascript时,contenteditable = true停止工作

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

Stack Overflow用户
提问于 2015-08-03 19:43:19
回答 1查看 79关注 0票数 0

嗨,我有一个文本框,当我实现contenteditable的时候,它运行的很好。但是当我实现jquery和javascript时,contenteditable完全停止工作了。我不知道这是否正常,任何帮助都是非常感谢的。

代码语言:javascript
复制
<!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

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

发布于 2015-08-03 20:04:58

.draggable()正在阻止可编辑行为。您可以如下所示来修复这个问题:

代码语言:javascript
复制
$.fn.makeEditable = function () {
    return this.each(function () {
        $(this).on('cilck mousedown', function () {
            $(this).focus();
        });
    });
};

$('.note').draggable().resizable().makeEditable();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31795489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档