jQuery Mobile的:
我有这样的代码:
$("#header ." + className).on("click",function(event)
{
var localValue = localStorage.getItem(selectedInstitut);
if (localValue === null) {
localStorage.setItem(selectedInstitut, "favorit");
console.log("Is NOT favorited. Doing that now")
$(this).buttonMarkup({theme: 'b'});
}
else {
localStorage.removeItem(selectedInstitut);
console.log("Is favorited. Unfavorited now!!")
$(this).buttonMarkup({theme: 'a'});
}
});
这正常一个的时间,但我有几个动态生成的页面相同的按钮(不同类的名称虽然)。 如果被点击一个页面上的按钮,我切换到另一个,它进入了IF进入else条件。 如果我切换到第3页,它进入了IF,ELSE,再次进入IF语句...等等为第4页。
任何想法?
我建议结合从文档事件代表团事件,包括它不会得到执行不止一次全局脚本。发生什么是每当您加载新页面时,代码再次执行,绑定另一个事件。 –
顺便说一句,''''用'id'选择。 –
你能更具体一点吗?我有点新的jQuery。 – lornz