Javascript iScroll中LI元素上的重复onClick事件
这是我的密码。。调用此函数时,iScroll()在更改页面后在LI元素上添加了重复事件Javascript iScroll中LI元素上的重复onClick事件,javascript,html,jquery-mobile,cordova,iscroll4,Javascript,Html,Jquery Mobile,Cordova,Iscroll4,这是我的密码。。调用此函数时,iScroll()在更改页面后在LI元素上添加了重复事件 function collectionOffen(asseID, imgsInFile) { $("#thelist").empty(); // append image files into slider div.. for (var imgPageCnt = 0; imgPageCnt <= imgsInFile; imgPageCnt++) { var html = "
function collectionOffen(asseID, imgsInFile) {
$("#thelist").empty();
// append image files into slider div..
for (var imgPageCnt = 0; imgPageCnt <= imgsInFile; imgPageCnt++) {
var html = "";
html += "<li id=" + imgPageCnt + ">";
html += "<img src='" + preThmb + "'>";
html += "</li>";
$("#thelist").append(html);
funcPreImg = function () {
previewImageBackside(asseID);
}
document.getElementById(imgPageCnt).addEventListener("click", funcPreImg);
}
$("#thelist").listview("refresh");
$.mobile.changePage("#collectionOfFiles", {
transition: "slide",
reverse: true
});
var myScroll = new iScroll('wrapper');
}
function collectionOffen(asseID,imgsinfle){
$(“#列表”).empty();
//将图像文件追加到slider div。。
对于(var imgPageCnt=0;imgPageCnt重复事件是jqm中的常见问题
尝试以下方法(untestet braincode):
$(文档).on('pageinit',函数(){
$(“#列表”).empty();
//将图像文件追加到slider div。。
对于(var imgPageCnt=0;imgPageCnt我找到了解决方案。在渲染图像后销毁iScroll对象
例如:-
var myScroll=new iScroll('wrapper');
myScroll.refresh();
myScroll.destroy()
将myScroll作为静态变量来销毁对象。当您注释iScroll()时,然后代码工作正常。iScroll添加了重复的事件。更新了我的示例,如果事件被处理,它将不会被执行两次这不是一个有效的解决方案,我之前说过-它应该将您推向正确的方向。如果iScroll与您的事件混在一起,也许您应该看看iScroll文档并了解其内部结构行为。通常,点击-点击或vclick在使用多页模板时可能会被触发多次,并且您正在从一个页面切换到下一个页面,然后再次切换(第二次、第三次、第四次访问页面)。事件会被触发(每次)当绑定到事件(例如在pageshow上)时,您将重新访问该页面。为避免此绑定,请按以下方式执行:$(文档)。关闭('click','.imgClass')。打开('click','.imgClass',函数(e){
建议id以字母而不是数字开头。
$(document).on('pageinit', function () {
$("#thelist").empty();
// append image files into slider div..
for (var imgPageCnt = 0; imgPageCnt <= imgsInFile; imgPageCnt++) {
var html = "";
html += "<li id='" + imgPageCnt + "' class='imgClass'>";
html += "<img src='" + preThmb + "'>";
html += "</li>";
$("#thelist").append(html);
}
//is 'asseID' defined in this context?
$(document).on('click', '.imgClass', function (e) {
if(e.handled !== true)
{
previewImageBackside(asseID);
e.handled = true;
}
});
$("#thelist").listview("refresh");
$.mobile.changePage("#collectionOfFiles", {
transition: "slide",
reverse: true
});
var myScroll = new iScroll('wrapper');
});