在文本框中复制粘贴时删除有序/无序项目符号

问题描述 投票:-3回答:1

在将文本从MS Word复制粘贴到html文本框时,子弹将附加在文本框中。如何使用Jquery / Javascript删除它?

enter image description here

javascript jquery html html.textbox
1个回答
0
投票

有很多方法可以从文本框中删除不需要的字符。一种方法是使用regualr表达式从该值字段中过滤掉任何非字母数字字符,并将过滤后的值放回文本框中,替换/覆盖旧值。

$('#my_textbox').keyup(function() {
  //this code will be triggered after each keystroke inside the textbox
  // alternatively, you may want to only trigger it after blur/change/etc

  var cleaned = $(this).val().replace(/^\s*[o\W]\s+/g, '');
  //removes any letter 'o' followed by spaces
  //removes any non-alphanumeric followed by spaces

  $(this).val(cleaned);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h3>Paste something here with a bullet point</h3>
<input type="text" id="my_textbox">
© www.soinside.com 2019 - 2024. All rights reserved.