首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript怎么使用正则比配有规律的html标签

2012-05-10 
javascript如何使用正则比配有规律的html标签要匹配的标签如下:input namerptQuestions:_ctl0:txtQuest

javascript如何使用正则比配有规律的html标签
要匹配的标签如下:


<input name="rptQuestions:_ctl0:txtQuestionType" type="text" value="1" id="rptQuestions__ctl0_txtQuestionType" style="width:0px;" />
<input name="rptQuestions:_ctl0:txtQuestionTypes" type="text" value="56" id="rptQuestions__ctl0_txtQuestionTypes" style="width:0px;" />

匹配整个标签,我要把字符合条件的标签删除。
其中主要以name和id中的txtQuestionType 做主要标识

改怎么样写正则表达式才可以删除name和ID中存在txtQuestionType 的整个标签


[解决办法]

JScript code
  var s='<input name="rptQuestions:_ctl0:txtQuestionType" type="text" value="1" id="rptQuestions__ctl0_txtQuestionType" style="width:0px;" /><input name="rptQuestions:_ctl0:txtQuestionTypes" type="text" value="56" id="rptQuestions__ctl0_txtQuestionTypes" style="width:0px;" />'var p=/<input\s*name=".*?(?:txtQuestionType)"[^>]*>/gi;alert(s.replace(p,''));
[解决办法]
探讨

如果用jQuery的话:
$("input[name^='rptQuestions'][id=^='rptQuestions']").remove();
“^=”配置以属性以给定字符串开头的元素

热点排行