Contenteditable paragraph tag on enter

后端 未结 3 1017
迷失自我
迷失自我 2020-12-30 05:01

I was wondering if there is an acceptable way to force all major browsers to insert paragraph tag instead of the default tag that they insert on pressing enter key when cont

3条回答
  •  执笔经年
    2020-12-30 05:26

    you can use document.execCommand('formatBlock', false, 'p'); in event like keypress or keydown, etc. to use paragraphs after enter press. For example:

    element.addEventListener('keypress', function(ev){
        if(ev.keyCode == '13')
            document.execCommand('formatBlock', false, 'p');
    }, false);
    

提交回复
热议问题