我有一个函数 Nextthing
可以隐藏第一个 iframe 并显示下一个 iframe,但是正如您将在该函数的代码中看到的那样,我只为下一个 iframe 执行了操作,所以如果他使第二个 iframe 的操作将其隐藏并显示它将显示的下一个 iframe,但显示在错误的位置。
如何让函数运行一次后停止?
function Nextthing (){
$("#i").hide();
$('.table').eq(1).find('tbody tr').eq(2).after(
'<tr><td colspan=10><iframe class="iframe" src="/msg.html?msgId=' +
$('.table').eq(1).find('tbody tr').eq(2)
.find('td a').eq(0).text()+'&constant=1"></iframe></td></tr>);
}
更新:正如您所看到的,iframe 是从该页面 msg.html 调用的,该页面有一个输入和一个提交按钮,并且在该按钮中调用函数 Nextthing
,如下所示:
<input type="submit" onclick="parent.Nextthing();" />
当有人按下 iframe 中的提交按钮时,它会根据 msgId 加载 msg.html 下一页的 iframe,而我希望只加载一次...
最佳答案
你可以使用
.one()
handler..它将运行代码一次并停止执行。
$('input[type=submit]').one('click', function() {
$("#i").hide();
$('.table').eq(1).find('tbody tr').eq(2).after('<tr><td colspan=10><iframe class="iframe"
src="/msg.html?msgId='+$('.table').eq(1).find('tbody tr').eq(2).find('td
a').eq(0).text()+'&constant=1"></iframe></td></tr>);
});
关于javascript - 执行一次后停止 jquery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12678852/