how do you strip html tags in textarea input

后端 未结 6 1663
自闭症患者
自闭症患者 2020-12-16 21:00

I have set up a little web application where you add post-its to a page. It\'s just a project to help better learn JavaScript/jQuery and it seemed like an appropriate projec

6条回答
  •  自闭症患者
    2020-12-16 21:49

    You have three issues: One is that the method is not returning properly (that's the fault of whoever wrote it). Next is that you are defining the method within $(document).ready(), so it is not able to be found (at least in Chrome). Third, you are not calling it the right way (onSubmit will never be used here).

    I've used @Joao's method (so you should upvote his answer) and used this method, moved outside of the ready() function:

    function stripHTML(str){
      var strippedText = $("
    ").html(str).text(); return strippedText; }​

    And also called it here:

    var post = stripHTML($(".text_input").val())
    

    Here is the working fiddle: http://jsfiddle.net/ee3MH/

提交回复
热议问题