0

使用基本 HTML 制作了一个表格并将其存储在一个变量 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 是一个包含字符串的数组,可以填充到表中。(方括号)在 getcontent

contentinsquare=["姓名","100$"]

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

 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>不起作用。我希望 100 美元在 thr 上被更换。

4

0 回答 0