Make selected text bold/unbold

后端 未结 8 1939
谎友^
谎友^ 2020-12-08 12:18

I\'m wrapping the selected text in span tags, when you click a button. If I then select a different piece of text and click the button, that text also gets wrapped in tags.

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 12:59

    If you are looking to use the keyboard to bold characters, you can use the following (Mac):

    $(window).keydown(function(e) {
      if (e.keyCode >= 65 && e.keyCode <= 90) {
        var char = (e.metaKey ? '⌘-' : '') + String.fromCharCode(e.keyCode)
        if(char =='⌘-B') {
        document.execCommand('bold')
        }
      }
    }) 
    

    Using keyboard to bold character:

提交回复
热议问题