Strip html tags before callback

2019-08-23 22:44发布

I use AjaxHelper.BeginForm to create ajax form in my view. The view has a textarea to provide content. How can I remove html tags from this textarea before form is submited. What I mean:

  • user clicks 'button'
  • tags are stripped
  • callback is made.

1条回答
Fickle 薄情
2楼-- · 2019-08-23 22:52

You can use a regular expression to remove HTML tags from a string, but note that it is not 100% reliable.

$("button").click(function() {
    var text = $("#someElement").val().replace(/(<([^>]+)>)/ig, "");

    // make callback with above variable...
});
查看更多
登录 后发表回答