【问题标题】:Script not working for search page and click link脚本不适用于搜索页面并单击链接
【发布时间】:2014-11-04 16:34:51
【问题描述】:

我有以下脚本

<script>
setTimeout(function() { window.location.reload(); }, 2000); // 2 seconds, e.g.

$('a:contains("13468100")').closest('tr').find('.fightActionInnerInner').click();
</script>

页面上有一个 iframe。该脚本应该在 iframe 的内容中搜索包含数字 13468100 的任何链接,然后单击它旁边的 tr,id 为“fightActionInnerInner”,每 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>

【问题讨论】:

  • 请向我们展示 HTML,没有它我们不知道您尝试做的是否正确。但是从你说的文字来看fightActionInnerInner是一个id而不是一个类find('#fightActionInnerInner')
  • 确保您想要的 tr 在 HTML 中您想要的锚标记之上。通过 DOM 查找 .closest 搜索向上而不是向下。
  • @SpencerWieczorek 我更新了帖子:)

标签: javascript


【解决方案1】:

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

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

这将执行您从脚本中描述的内容。它会找到该类的所有 tr (我认为你的意思是类不是 Id,但如果你真的想要一个 Id,只需将 . 更改为 #),它有一个包含你想要的任何东西的孩子的链接。

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

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

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

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

【讨论】:

  • @Keith...我更新了我的朋友的帖子...并尝试了您的建议。我仍然无法让它工作:(
  • 是不是因为脚本搜索的是父页面而不是 iframe 内容?
  • 这可能就是原因。检查链接以获取 iframe 内容,然后在这些内容的上下文中尝试查询。 stackoverflow.com/questions/1088544/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 2011-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多