【问题标题】:How to remove html element while leaving the text inside input value untouched?如何删除 html 元素,同时保持输入值中的文本不变?
【发布时间】:2019-04-14 11:37:13
【问题描述】:

需要从输入的值标签中删除标签。

该元素是由主机的 CMS 生成的,因此我可以删除粗体标签的唯一方法是运行脚本。

<span id="kkkje30">
<input type="text" id="siF14" class="manFlPassw" value="<b>generated text</b>" maxlength="15">
</span>

【问题讨论】:

  • 试试这样的: var StrippedString = OriginalString.replace(/(]+)>)/ig,"");然后您可以将输入的值设置为“strippedString”

标签: html css jscript


【解决方案1】:

您可以像这样使用正则表达式删除输入值中的标签

$(document).ready(function(){
  $('input').each(function(index, item){
    var regex = /(<([^>]+)>)/ig;
    var value = $(item).val();
    var removedtag = value.replace(regex, '');
    $(this).val(removedtag);
  });
})

演示:

$(document).ready(function(){
  $('input').each(function(index, item){
    var regex = /(<([^>]+)>)/ig;
    var value = $(item).val();
    var removedtag = value.replace(regex, '');
    $(this).val(removedtag);
  });
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span id="kkkje30">
<input type="text" id="siF14" class="manFlPassw" value="<b>generated text</b>" maxlength="15">
</span>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-25
    • 2015-04-05
    • 2019-10-03
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多