Placeholder for contenteditable div

后端 未结 12 1553
栀梦
栀梦 2020-12-12 23:18

I have the following: FIDDLE

The placeholder works fine and dandy until you type something, ctrl + A, and delete. If you do that, th

12条回答
  •  感情败类
    2020-12-13 00:07

    As swifft said, you can fix this with some super simple JS. Using jQuery:

    var $input = $(".test");
    $input.keyup(function () {
        if ($input.text().length == 0) {
            $input.empty();
        }
    });
    

    On each keystroke it checks whether there's any input text present. If not, it whacks any child elements that may have been left behind by user interaction with the element -- e.g. the

    swifft describes.

提交回复
热议问题