Javascript Regex replace在IE10中不起作用

Javascript Regex replace not working in IE10

本文关键字:不起作用 IE10 Regex replace Javascript      更新时间:2023-09-26

以下JS在FF中运行良好,但不会取代IE10中的任何东西:

var pattern = new RegExp('<span id='"(.+?)'" class='"questiontext'"><p(.*?)>(.+?)<'/p><'/span>', 'gim');
$('.questiontext_div').html(function(index, html) { return html.replace(pattern,'<span id="$1" class="questiontext"><legend>$3</legend></span>'); });

我正试图用一个传说来代替p。

<div class="questiontext_div">
  <span id="C00B7205241531FD2BEF31301000101F0DESC" class="questiontext">
     <P style="font-weight: bold; color: #005881;">Text will go here!</P>
  </span>
</div>

这可能更简单:

$('span.questiontext p').replaceWith('<legend...etc>');

并在所有浏览器上工作