简体   繁体   English

javascript getElementById重新填充多行

[英]javascript getElementById repopulate for multiple rows

I'm getting some stuff from the web formular using: 我正在使用以下方法从Web公式器中获取一些东西:

 echo "<tr>";
 echo "<td>" . $row['platform_name'] . "</td>";
 echo "<td><input name='id[]' type='hidden' value='".$row['id']."' /><input name='id_acc_ref[]' type='hidden' value='".$row['id_acc_ref']."' /><input name='platform_type[]' type='hidden' value='".$row['platform_type']."' /><input name='platform_name[]' type='hidden' value='".$row['platform_name']."' />Every <input id='scan_freq1' name='scan_freq1[]' type='number' style='width:50px;text-align:center' min='0' max='256' value='".$row['scan_frequency']."' placeholder='0000-00-00' /> week(s)</td>";
 echo "<td><input type='text' class='datepicker' name='first_scan_date1[]' style='text-align:center' value='".$row['first_scan_date']."' placeholder='0000-00-00' /></td>";
 echo "<td><input id='next_scan_date1' name='next_scan_date1[]' type='text' readonly='readonly' style='text-align:center' placeholder='".$row['next_scan_date']."' /></td>";
 echo "<td style='text-align:center'><img src='../images/ok.gif' id='save_conf1'></td>";
 echo "</tr>"; 

As you know, they're all arrays, that depends of the numbers of elements in the database. 如您所知,它们都是数组,这取决于数据库中元素的数量。 I've got some simple code, getting the result from the database and based on them, I'd like to make images visible in scope of that form (that submit button covers). 我有一些简单的代码,可以从数据库中获取结果,并基于这些结果,使图像在该表单(提交按钮封面)的范围内可见。

function test(resp)
  {
    if (resp == 1) 
    {
        document.getElementById('save_conf1').style.visibility = 'visible';
    }

But it does visible's me after update just the first element (image), no matter which I select, any ideas how to populate it for all? 但是,仅更新第一个元素(图像)之后,它对我来说是可见的,无论我选择哪个元素,有什么想法如何全部填充它?

Thanks in advice. 感谢您的建议。

If each <img src=...> has a unique id ( id='save_conf1' , id='save_conf2' , id='save_conf3' , etc. ) you can use a for loop - 如果每个<img src=...>具有唯一的idid='save_conf1'id='save_conf2'id='save_conf3' etc. ),则可以使用for循环-

function test(resp)
  {
    if (resp == 1) 
    {
        var max = ... //total number of <img src=...> with id='save_conf#'
        for (var i=1;i<=max;i++)
        { 
        document.getElementById('save_conf'+i).style.visibility = 'visible';
        }
    }

Another way to do it would be to use class and getElementByClassName . 另一种方法是使用classgetElementByClassName
ie. 即。 <img src=... class='save_conf'>

function test(resp)
  {
    if (resp == 1) 
    {
        document.getElementByClassName('save_conf').style.visibility = 'visible';

    }

Using getElementByClassName works on most modern browsers, but not on IE < 8. see also - stackoverflow.com/questions/1933602/how-to-getelementbyclass-instead-of-getelementbyid-with-javascript 使用getElementByClassName可在大多数现代浏览器上使用,但不适用于IE <8。另请参见-stackoverflow.com/questions/1933602/how-to-getelementbyclass-in-of-getelementbyid-with-javascript

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

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