Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

javascript - 有没有办法使用JavaScript使用完整字符串的一部分来获取它?(Is there a way to get the Complete String using a portion of it using JavaScript?)

In a GridView, the name of the table is getting generated dynamically.

(在GridView中,表的名称是动态生成的。)

but it will have the dynamic Name with GridView ID gets appended.

(但它会附加带有GridView ID的动态名称。)

something Like "w123443dsfnsbd32dkkd_GridView1".

(类似于“ w123443dsfnsbd32dkkd_GridView1”。)

so first part will always keep changing whenever we reloads the grid.

(因此,每当我们重新加载网格时,第一部分将始终保持变化。)

so I would like to get the name of the Grid with "_GridView1", with this I would like to fetch the complete Grid Name.

(因此我想使用“ _GridView1”获取网格的名称,并以此获取完整的网格名称。)

So Is there a way to look for this?

(那么有没有办法寻找呢?)

I tried this var table = document.getElementById("GridView1");

(我试过这个var table = document.getElementById("GridView1");)

but didn't work.

(但是没有用)

Code:

(码:)

var table = document.getElementById("wcwidget_df5339c463eedb_widget_gridView1");

if (table.rows.length > 0) {


    for (var i = 0 ; i < table.rows.length; ++i) {


        if (table.rows[i].cells[0].innerText == "Company1" || table.rows[i].cells[0].innerText == "Company2" ||
            table.rows[i].cells[0].innerText == "Company5" ) 
    {
            for (var k = 1; k < table.rows[i].cells.length; ++k) {
                table.rows[i].cells[k].style.fontWeight = "bold";
                table.rows[i].cells[k].style.color = "black";
            }

        }

    }

    for (var i = 0 ; i < table.rows.length; ++i) {
        if (table.rows[i].cells[0].innerText == "Risk" || table.rows[i].cells[0].innerText == "Medium Risk" || table.rows[i].cells[0].innerText == "High Risk" ) {
            table.rows[i].cells[0].style.fontWeight = "bold";
            table.rows[i].cells[0].style.color = "black";
        }
    }

}
  ask by Tim translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this:

(尝试这个:)

document.querySelectorAll("[id*='GridView1']")

this will return an array.

(这将返回一个数组。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...