从html字符串中识别和替换格式化的日期范围

时间:2016-03-20 10:23:29

标签: javascript jquery

我有一个以下的html字符串,其中必须替换日期范围。

 var htmlStr = "<strong>1-Mar-2015</strong>"+
     "<span> to </span>"+
     "<strong>15-Feb-2016</strong><br>"+
     "<span>by </span>"+
     "<strong>Week</strong><br>"+
     "<span>Key</span>"+
     "<span> is </span>"+
     "<strong>Key Value</strong><br>"+
     "<span>Type</span>"+
     "<span> is </span>"+
     "<strong>Report</strong>"+
     "<span> or </span>"+
     "<strong>Incident</strong><br>"+
     "<span>SomeKey</span>"+
     "<span> is </span>"+
     "<strong>SomeValue</strong>";

我想用某个特定的日期范围替换日期范围。 现在我打破带有br标签的html字符串来划分不同的属性并尝试替换第一个和第二个强标记的内容。

我正在寻找可能的Regex解决方案来替换日期范围。

js代码流程如下:

var startdate = '2-Jun-2012';//selected from dom
var enddate = '24-Sept-2014';//selected from dom
for(var i = 0; i < IDList.length; i++ ) {
    var htmstr = loadHtmlDataFromServer(IDList[i]); //will get html type content from server
    //if startdate and enddate value exist, update htmstr
    CreateModal(htmlstr, IDList[i]);
}

1 个答案:

答案 0 :(得分:1)

你标记了这个jQuery:

img1.Source = (ImageSource)e.Data.GetData(typeof(ImageSource));