Save selection text and show it later in html and javascript

后端 未结 8 911
悲哀的现实
悲哀的现实 2020-12-14 18:39

I have a difficult situation with html and javascript. My html page allows user to select text and highlight it with colors. Now I want to save the state into database to sh

8条回答
  •  爱一瞬间的悲伤
    2020-12-14 19:01

    from a testing perspective, there is no way to store detached highlights if it is possible to alter the original html without also adjusting the highlights.

    my solution would be to serialize the entire colored html. then make a scrub function to remove all color highlights and return to the baseline html. this allows the html in the db to include the color highlights and editing can still occur with highlighting preserved.

    something like:

    function unhighlight() {
      $('.highlighted').each(function(index, el) {
        $(el).replaceWith($(el).html());
      });
    }
    

    jsfiddle: https://jsfiddle.net/tobtedsc/5/

提交回复
热议问题