[英]Too much recursion in JavaScript
I have this JavaScript which opens new page: 我有这个JavaScript,可以打开新页面:
$(document).ready(function () {
//$('a[id$="lnkHidden"]').trigger("click"); // Not sure if this is actually necessary
$('table[id$="dataTable"]').find("tbody").on("click", "tr", function () {
$(this).find('a[id$="lnkHidden"]').trigger("click");
});
});
This is the button which is called by the JS script: 这是JS脚本调用的按钮:
<h:commandLink id="lnkHidden" action="#{bean.pageRedirect}" style="text-decoration:none; color:white; display:none">
</h:commandLink>
After I click on a table row I get this error message: 单击表格行后,出现以下错误消息:
too much recursion [Break On This Error] ...,c=l.length;c--;)(f=l[c])&&(v[d[c]]=!(y[d[c]]=f));if(i){if(o||e){if(o){for(l=[],...
Can you help me to fix this? 你能帮我解决这个问题吗?
You can cut the infinite loop with those changes from your original code 您可以使用原始代码中的更改来切入无限循环
.trigger("click", [ true ])
.trigger("click", [ true ])
function(event, simulated)
function(event, simulated)
simulated || $(this).find('a[id$="lnkHidden"]').trigger("click", [ true ]);
simulated || $(this).find('a[id$="lnkHidden"]').trigger("click", [ true ]);
simulated || $(this).find('a[id$="lnkHidden"]').trigger("click", [ true ]);
However that event triggering and that kind of selectors are not recommended. 但是,不建议使用事件触发和这种选择器。
Instead of triggering synthetic click events, you could just change the current URL directly: 除了触发综合点击事件,您还可以直接更改当前URL:
$(document).ready(function () {
$('table[id$="dataTable"]').find("tbody").on("click", "tr", function () {
var links = $(this).find('a[id$="lnkHidden"]');
if(links.length && links[0].href) {
window.location.href = links[0].href;
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.