【发布时间】: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