用dojo和javascript替换HTML内容

时间:2012-10-14 09:35:15

标签: javascript jquery html dojo

使用基本HTML创建了一个表并将其存储在varle getcontent中。

getcontent="<table style="height: 1000px; ; width: 500px;" border="1">
    <tbody>
    <tr>
    <td>[Assignment name]</td>
    <td>[<span>Approximate Value of Contract</span>]</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </tbody>
    </table>"

Contentinsquare是一个包含字符串的数组,可以在表中填充。 getqutent中的(SQUARE BRACKETS)

contentinsquare = [ “名称”, “$ 100”]

我希望contentinsqaure的值放在sqaure括号之间。为此我使用了代码: -

 var contentinsquare=["name","100$"]
  var  strInputCode = contentinsquare[1].replace(/&(lt|gt);/g, function (strMatch, p1){
                return (p1 == "lt")? "<" : ">";
            });
            var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");

    contentinsquare[1]=strTagStrippedText


var strforlabelname = []
    var strfortextarea = []
    var strfortext = []
    var str = []
    label = dojo.query('label');
    console.log(label, "all label names")
    for( i = 0; i < label.length; i++)
    {
        if(label[i].id != "")
        {
            inner = dojo.byId(label[i].id).innerHTML
            var name = inner.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
            strforlabelname.push(name)
        }
    }
    console.log(strforlabelname, "string")
    text = dojo.query('input')
    for( i = 0; i < text.length; i++)
    {
        if(text[i].id == "")
        {

        }
        else
        {
            innertext = dijit.byId(text[i].id).getValue();

            str.push(innertext)
//console.log(str,"strng1")
        }
    }
    textarea = dojo.query('textarea')
    for( i = 0; i < textarea.length; i++)
    {
        if(textarea[i].id == ""||textarea[i].id =="textareaidfirst")
        {

        }
        else
        {
            innertextarea = dojo.byId(textarea[i].id).value
            str.push(innertextarea)

        }
        }
for( i = 0; i < strforlabelname.length; i++)
        {
    for( j = 0; j < contentinsquare.length; j++)
    {

            if(contentinsquare[j] == strforlabelname[i])
            {
                var patt = new RegExp("\\[" + strforlabelname[i] + "\\]", "g")
                getcontent = getcontent.replace(patt, str[i]);



            }

        }

}

This results to :-

结果: -

"<table style="height: 1000px; ; width: 500px;" border="1">
<tbody>
<tr>
<td>name</td>
<td>[<span>Approximate Value of Contract</span>]</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>"

这是包含<span>标记的sqaure括号不起作用。我希望100美元被替换为thr。

0 个答案:

没有答案