简体   繁体   English

Javascript / XML / HTML清除并重写

[英]Javascript/XML/HTML Clear and rewrite

With this Javascript code: 使用此Javascript代码:

            arrLocations = xmlHTTP.responseText.split("~");
        for (i = 0; i < arrLocations.length; i++){

            // Extract the info for this button.
            strLocation = arrLocations[i];
            arrLocation = strLocation.split(";");

            // Populate the contents of this button.
            elTemp = document.getElementById('loc' + arrLocation[0]);
            if (arrLocation[2].length > 0)
                elTemp.innerHTML = elTemp.innerHTML + '<br><span style="font-size: 12px; font-weight: bold;">' + arrLocation[2] + ' ' + arrLocation[3] + '</span><br><span style="font-size: 10px;"> (' + arrLocation[4] + ')' + '</span><br>';
            else
                elTemp.innerHTML = arrLocation[1];

        }

I am writing to the inside of a button... To display a name and date etc... Like this example: 我正在写按钮的内部...显示名称和日期等...像这个例子:

在此处输入图片说明

Here is the button HTML: 这是按钮HTML:

<table align="center" cellpadding="3" cellspacing="3" border="0">

                        <tr>
                            <td width="30%" align="center" valign="middle" id="loc1" nowrap style="cursor: hand; font-size: 36px; border: 9px outset orangered;" class="bodyText" onClick="updateLocationTable(1);">Finesse</td>

                            <td width="5%" align="center" valign="middle" nowrap class="bodyText"></td>
                            <td width="30%" align="center" valign="middle" id="loc2" nowrap style="cursor: hand; font-size: 36px; border: 9px outset orangered;" class="bodyText" onClick="updateLocationTable(2);">Rework</td>

                            <td width="5%" align="center" valign="middle" nowrap class="bodyText"></td>
                            <td width="30%" align="center" valign="middle" id="loc3" nowrap style="cursor: hand; font-size: 36px; border: 9px outset orangered;" class="bodyText" onClick="updateLocationTable(3);">OP/Masking</td>
                        </tr>
                        <tr>
                            <td align="center" valign="middle" colspan="3" nowrap class="bodyText">&nbsp</td>
                        </tr>

                </table>

My problem is that every time I call this function... It does not clear what is already in the button, it just writes over the top of that... How can I clear what is inside that button's HTML before I do another rewrite? 我的问题是,每次调用此函数时,...不会清除按钮中已有的内容,而只是覆盖其顶部...在执行另一次重写之前,如何清除按钮HTML中的内容?

When I do another add, it ends up looking like this: It keeps the previous write, then rewrites again just adding one... So if A and B are logged the screen shows A + B... if C tries to log in... It keeps A + B but then rewrites A + B and adds C so we end up with A+B+A+B+C 当我进行另一次添加时,它最终看起来像这样:保留先前的写操作,然后再次重写,仅添加一个...。因此,如果记录了A和B,则屏幕显示A + B ...如果C尝试登录...保留A + B,然后重写A + B并添加C,所以我们最终得到A + B + A + B + C

在此处输入图片说明

Just so everybody knows... I solved the problem with a simple location.reload() 所有人都知道...我用一个简单的location.reload()解决了这个问题

I put this inside the function that is called when the button is pressed... This allowed the additional write to happen, but also refreshed the page which would load only whats in the database, which was the correct information anyway... I am basically just hiding the problem but it works for what I need it for! 我将其放在按下按钮时调用的函数中...这允许进行额外的写入操作,但是还刷新了仅加载数据库中内容的页面,无论如何这都是正确的信息...我是基本上只是隐藏问题,但它可以满足我的需求!

Thanks for all the helpful suggestions! 感谢所有有用的建议!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM