脚本不适用于搜索页面并单击链接

Script not working for search page and click link

本文关键字:单击 链接 不适用 适用于 搜索 脚本      更新时间:2023-09-26

我有以下脚本

<script>
setTimeout(function() { window.location.reload(); }, 2000); // 2 seconds, e.g.
$('a:contains("13468100")').closest('tr').find('.fightActionInnerInner').click();
</script>

页面上有一个iframe。该脚本应该在iframe的内容中搜索包含数字13468100的任何链接,然后单击其旁边id为"fightActionInnerInner"的tr,每2秒刷新一次页面。

刷新功能有效,但脚本似乎没有点击链接,尽管我知道它在那里。

此外,我希望有一个输入框,用户可以在其中输入他们需要脚本搜索的内容。例如:如果他们想搜索包含"David"的链接,他们只需在文本框中键入David,它就会修改脚本。

这是我要求脚本搜索的html

<td class="fightMobster">
<div>
    <a href="/profile.php?puid=5562089&formNonce=34947b8ffc73e8ceafabae71…94f&setTab1Badge=&h=2d55f5781bfe888b47d7f5c9dbc27df2f663347f">
        Lord Pookie
    </a>
</div>
<div>
    Lvl 212 Daywalker
</div>
</td>
<td class="fightSp"></td>
<td class="fightMobSize">
<span class="cash">
    <span style="white-space: nowrap;">
        <img width="15" height="14" style="padding-right:2px" src="http://static.storm8.com/zl/images/flesh.png?v=330"></img>
        15,300
    </span>
</span>
</td>
<td class="fightSpLg"></td>
<td class="fightAction">
<script>

            function fsb99995143() {
              var b=…
</script>
<a onclick="return fsb99995143();" href="/hitlist.php?tab=fight.php&action=fight&hitlistId=99995143&f…1b4b9390bee9a194f&h=284e4fe4946e6fb8af3a662f4583454eebc8bd23">
    <div class="fightActionInner">
        <div class="fightActionInnerInner">
            Attack
        </div>

我认为一个更好、更简单的搜索查询是:

$(".fightActionInnerInner a:contains('13468100')").click();

这将执行您在脚本中描述的操作。它会找到该类的所有tr(我想你指的是类而不是Id,但如果你真的想要一个Id,只需将.更改为#),该类作为子级具有包含你想要的任何内容的链接。

要使其自定义,您需要添加一个变量:

var name = $("#INPUT_ID").val();

然后将其附加到您的查询中:

$(".fightActionInnerInner a:contains('" + name + "')").click();