jquery 通过 id 选择范围

发布于 2024-10-09 07:43:32 字数 4664 浏览 3 评论 0原文

大家好 有时你只是丢失了它,你甚至不记得如何搜索你丢失的东西,

 <div>
        <table cellspacing="0" rules="all" border="1" id="ctl00_DefaultContent_migrationGridView" style="height:90%;width:100%;border-collapse:collapse;">
            <tr>
                <th scope="col">&nbsp;</th><th scope="col">Lenda</th><th scope="col">CSV Dosje</th><th scope="col">Gjendje</th><th scope="col">Dat&#235;</th><th scope="col">Njoftim</th><th scope="col">&nbsp;</th>
            </tr><tr>
                <td>
                                    <input type="submit" name="ctl00$DefaultContent$migrationGridView$ctl02$Button1" value="Fshije" id="ctl00_DefaultContent_migrationGridView_ctl02_Button1" />
                                </td><td>
                                    <a id="ctl00_DefaultContent_migrationGridView_ctl02_CaseLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl02$CaseLinkButton','')" style="font-weight:bold;">mig1</a>
                                </td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl02_lblCSVFileName">19_71914066_2010-11-11_0849_ENG_SOFALI.csv</span>
                                    &nbsp;&nbsp;
                                </td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl02_Label2" style="color:Maroon;font-weight:bold;">Read</span>
                                </td><td>2010-12-28</td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl02_Label3"></span>
                                </td><td>

                                    <a id="ctl00_DefaultContent_migrationGridView_ctl02_startStopLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl02$startStopLinkButton','')">Start migration</a>
                                    &nbsp;
                                    <a id="ctl00_DefaultContent_migrationGridView_ctl02_checkedAllLinkButton" title="Të Kontrolluara" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl02$checkedAllLinkButton','')">Të Kontrolluara</a>
                                </td>
            </tr><tr>
                <td>
                                    <input type="submit" name="ctl00$DefaultContent$migrationGridView$ctl03$Button1" value="Fshije" id="ctl00_DefaultContent_migrationGridView_ctl03_Button1" />
                                </td><td>
                                    <a id="ctl00_DefaultContent_migrationGridView_ctl03_CaseLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl03$CaseLinkButton','')" style="font-weight:bold;">mig1</a>
                                </td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl03_lblCSVFileName">19_71914070_2010-11-11_0850_ENG_TRUDE.csv</span>
                                    &nbsp;&nbsp;
                                </td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl03_Label2" style="color:Maroon;font-weight:bold;">Read</span>
                                </td><td>2010-12-28</td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl03_Label3"></span>
                                </td><td>

                                    <a id="ctl00_DefaultContent_migrationGridView_ctl03_startStopLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl03$startStopLinkButton','')">Start migration</a>
                                    &nbsp;
                                    <a id="ctl00_DefaultContent_migrationGridView_ctl03_checkedAllLinkButton" title="Të Kontrolluara" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl03$checkedAllLinkButton','')">Të Kontrolluara</a>
                                </td>
            </tr>
        </table>
    </div>

有人可以告诉我如何迭代在 id 'lblCSVFileName' 上有这个字符串的跨度吗 值

并获取第一行的 ,我应该得到 19_71914066_2010-11-11_0849_ENG_SOFALI.csv ,第二行的值 19_71914070_2010-11-11_0850_ENG_TRUDE.csv

:(又是糟糕的一天

hello guys
some times you just loose it and you cant event remember how to search that that you lost

 <div>
        <table cellspacing="0" rules="all" border="1" id="ctl00_DefaultContent_migrationGridView" style="height:90%;width:100%;border-collapse:collapse;">
            <tr>
                <th scope="col"> </th><th scope="col">Lenda</th><th scope="col">CSV Dosje</th><th scope="col">Gjendje</th><th scope="col">Datë</th><th scope="col">Njoftim</th><th scope="col"> </th>
            </tr><tr>
                <td>
                                    <input type="submit" name="ctl00$DefaultContent$migrationGridView$ctl02$Button1" value="Fshije" id="ctl00_DefaultContent_migrationGridView_ctl02_Button1" />
                                </td><td>
                                    <a id="ctl00_DefaultContent_migrationGridView_ctl02_CaseLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl02$CaseLinkButton','')" style="font-weight:bold;">mig1</a>
                                </td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl02_lblCSVFileName">19_71914066_2010-11-11_0849_ENG_SOFALI.csv</span>
                                      
                                </td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl02_Label2" style="color:Maroon;font-weight:bold;">Read</span>
                                </td><td>2010-12-28</td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl02_Label3"></span>
                                </td><td>

                                    <a id="ctl00_DefaultContent_migrationGridView_ctl02_startStopLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl02$startStopLinkButton','')">Start migration</a>
                                     
                                    <a id="ctl00_DefaultContent_migrationGridView_ctl02_checkedAllLinkButton" title="Të Kontrolluara" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl02$checkedAllLinkButton','')">Të Kontrolluara</a>
                                </td>
            </tr><tr>
                <td>
                                    <input type="submit" name="ctl00$DefaultContent$migrationGridView$ctl03$Button1" value="Fshije" id="ctl00_DefaultContent_migrationGridView_ctl03_Button1" />
                                </td><td>
                                    <a id="ctl00_DefaultContent_migrationGridView_ctl03_CaseLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl03$CaseLinkButton','')" style="font-weight:bold;">mig1</a>
                                </td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl03_lblCSVFileName">19_71914070_2010-11-11_0850_ENG_TRUDE.csv</span>
                                      
                                </td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl03_Label2" style="color:Maroon;font-weight:bold;">Read</span>
                                </td><td>2010-12-28</td><td>
                                    <span id="ctl00_DefaultContent_migrationGridView_ctl03_Label3"></span>
                                </td><td>

                                    <a id="ctl00_DefaultContent_migrationGridView_ctl03_startStopLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl03$startStopLinkButton','')">Start migration</a>
                                     
                                    <a id="ctl00_DefaultContent_migrationGridView_ctl03_checkedAllLinkButton" title="Të Kontrolluara" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl03$checkedAllLinkButton','')">Të Kontrolluara</a>
                                </td>
            </tr>
        </table>
    </div>

can somebody tell me how to iterate through spans that have this string on the id 'lblCSVFileName'
and get their values

for the first row i should get 19_71914066_2010-11-11_0849_ENG_SOFALI.csv and for the second
19_71914070_2010-11-11_0850_ENG_TRUDE.csv

:( another bad day

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃扇骨 2024-10-16 07:43:32

您可以使用 属性结尾选择器 作为 ID 和 .map() 获取字符串数组(每个字符串中的文本),例如this:

var arr = $("span[id$='lblCSVFileName']").map(function() { 
            return $(this).text(); 
          }).get();

或者,一个稍微优化的未发布版本:

var arr = $("span[id$='lblCSVFileName']").map(function() { 
            return $.text([this]); 
          }).get();

这将为您提供一个可以使用的值数组,例如:

["19_71914066_2010-11-11_0849_ENG_SOFALI.csv", "19_71914070_2010-11-11_0850_ENG_TRUDE.csv"...]

You can use an attribute ends-with selector for the ID and .map() to get an array of strings (the text inside each), like this:

var arr = $("span[id$='lblCSVFileName']").map(function() { 
            return $(this).text(); 
          }).get();

Or, a slightly more optimized unpublished version:

var arr = $("span[id$='lblCSVFileName']").map(function() { 
            return $.text([this]); 
          }).get();

This would get you an array of values to work with, for example:

["19_71914066_2010-11-11_0849_ENG_SOFALI.csv", "19_71914070_2010-11-11_0850_ENG_TRUDE.csv"...]
宫墨修音 2024-10-16 07:43:32

以下代码将为您提供所需的内容。
它获取 ID 以“ctl00_DefaultContent_migrationGridView_ctl02_”开头的所有范围。

$('span[id^="ctl00_DefaultContent_migrationGridView_ctl02_"]').each(function() {
  //the following will give you the text of each span
  $(this).text();
});

注意:我会向每个跨度添加一个类,并使用它进行 jquery 选择。

The following code will give you what you need.
It gets all spans that have an ID that starts with "ctl00_DefaultContent_migrationGridView_ctl02_".

$('span[id^="ctl00_DefaultContent_migrationGridView_ctl02_"]').each(function() {
  //the following will give you the text of each span
  $(this).text();
});

NOTE: I would add a class to each span and do a jquery select using that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文