• 请不要在回答技术问题时复制粘贴 AI 生成的内容
youla
V2EX  ›  程序员

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

  •  1
     
  •   youla · Dec 29, 2020 · 4216 views
    This topic created in 2138 days ago, the information mentioned may be changed or developed.

    如题!

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

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

    <body>
    <style contenteditable style="display: block;">
    .test {
    color: #f00;
    }
    </style>
    <div class="test">
    text
    </div>
    </body>
    youla
    youla
    OP
    Dec 29, 2020
    12
    @DOLLOR 对不起,想象力不够丰富,原来是这么个 style~~
    aaronlam
    aaronlam
    Dec 29, 2020
    13
    @DOLLOR 这个操作很骚,貌似 <link> 标签也行。。
    nortonlai
    nortonlai
    Dec 29, 2020 via Android
    14
    大开眼界
    TargaryenChen
    TargaryenChen
    Dec 30, 2020
    15
    一些 web 上的 editor 组件就用的 contenteditable 实现的,例如 quill editor 。
    SpencerCoding
    SpencerCoding
    Dec 30, 2020
    16
    <div contenteditable="true">I'm Editable. Edit me!</div>
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2167 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 13:46 · PVG 21:46 · LAX 05:46 · JFK 08:46
    ♥ Do have faith in what you're doing.