V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
youla
V2EX  ›  程序员

一个奇怪的需求,前端不用“input or textarea”,实现输入框的功能,你会怎么做?

  •  1
     
  •   youla · 2020-12-29 21:29:39 +08:00 · 2813 次点击
    这是一个创建于 1207 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题!

    是我落后了,原来这样也行~~

    <div class="content" contenteditable="true"></div>
    
    16 条回复    2020-12-30 09:12:19 +08:00
    ysc3839
        1
    ysc3839  
       2020-12-29 21:33:00 +08:00 via Android   ❤️ 1
    heroes3top
        2
    heroes3top  
       2020-12-29 21:33:31 +08:00
    中文输入有其他唤起输入法的控件吗 = =
    shintendo
        3
    shintendo  
       2020-12-29 21:39:06 +08:00
    各种富文本编辑器控件都是用这个做的
    CismonX
        4
    CismonX  
       2020-12-29 21:39:15 +08:00 via iPhone
    我第一反应是用 canvas 😐
    JinTianYi456
        5
    JinTianYi456  
       2020-12-29 21:40:04 +08:00
    我上个月知道吧 [doge]
    westoy
        6
    westoy  
       2020-12-29 21:50:14 +08:00
    wysiwyg 编辑器都是基于这个的
    DOLLOR
        7
    DOLLOR  
       2020-12-29 21:50:50 +08:00
    contenteditable="true"
    富文本编辑都是用这个实现的。
    你甚至可以把它加载 style 标签上。
    autoxbc
        8
    autoxbc  
       2020-12-29 22:03:04 +08:00
    原生控件有 onchange 和 oninput 事件,自己搞的就没了
    youla
        9
    youla  
    OP
       2020-12-29 22:03:57 +08:00
    @DOLLOR,写 style 不行啊,大屁眼子!!
    youla
        10
    youla  
    OP
       2020-12-29 22:08:15 +08:00   ❤️ 1
    @autoxbc 用 contenteditable="true"属性还是有的
    DOLLOR
        11
    DOLLOR  
       2020-12-29 22:11:11 +08:00   ❤️ 3
    @youla

    <body>
    <style contenteditable style="display: block;">
    .test {
    color: #f00;
    }
    </style>
    <div class="test">
    text
    </div>
    </body>
    youla
        12
    youla  
    OP
       2020-12-29 22:13:45 +08:00
    @DOLLOR 对不起,想象力不够丰富,原来是这么个 style~~
    aaronlam
        13
    aaronlam  
       2020-12-29 22:33:44 +08:00
    @DOLLOR 这个操作很骚,貌似 <link> 标签也行。。
    nortonlai
        14
    nortonlai  
       2020-12-29 23:25:25 +08:00 via Android
    大开眼界
    TargaryenChen
        15
    TargaryenChen  
       2020-12-30 09:04:38 +08:00
    一些 web 上的 editor 组件就用的 contenteditable 实现的,例如 quill editor 。
    SpencerCoding
        16
    SpencerCoding  
       2020-12-30 09:12:19 +08:00
    <div contenteditable="true">I'm Editable. Edit me!</div>
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3108 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:15 · PVG 08:15 · LAX 17:15 · JFK 20:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.