jQuery 点击事件问题 - Framework7
jQuery Click Event Issue - Framework7
所以我有几个问题。第一个...我有 2 页,一个 products.html
页和一个 search.html
页。 products.html
页面在 .onPageAfterAnimation() 中运行一些 Ajax;从数据库中获取产品并显示它们。返回的 HTML 包含用户可以在文本框中增加和减少数字值的部分。
当我打开 products.html
页面时,将值增加或减少 1 的按钮最初起作用,但是,当我进入 search.html
并返回到 products.html
时页面使用我的 Android 的后退按钮(我有 pushState = true
)并按 increase/decrease 按钮 increases/decreases 2。如果我再次尝试做同样的事情 increases/decreases 乘以 3 等等……
这是我 products.html 页面中的 increase/decrease 代码:
myApp.onPageAfterAnimation('catalogs', function (page) {
//Increse/decrease product quantity
$(“.promo-screen-content”).on(“click”, “.addToCartBtn”, function(){
var productid = $(this).attr(“data-productId”),
currentvalue = parseInt($('#txtQuantity' + productid).val());
$('#txtQuantity' + productid).val((currentvalue + 1).toString());
});
$(“.promo-screen-content”).on(“click”, “.removeFromCartBtn”, function(){
var productid = $(this).attr(“data-productId”),
currentvalue = parseInt($('#txtQuantity' + productid).val());
if(currentvalue > 1){
$('#txtQuantity' + productid).val((current_value – 1).toString());
}
});
});
有人知道为什么会发生这种情况以及如何解决它吗?
我的第二个问题有点不同。每当我单击一个按钮时,它都会单击并执行该过程 3 或 4 次。因此,例如,如果我在单击时显示通知,它会显示该通知 3 或 4 次。
我不知道这些是否普遍或人们遇到过的问题。非常感谢任何帮助!
我将我的代码放入错误的页面回调中。我不得不把它放在 .onPageInit();
回调中。
所以我有几个问题。第一个...我有 2 页,一个 products.html
页和一个 search.html
页。 products.html
页面在 .onPageAfterAnimation() 中运行一些 Ajax;从数据库中获取产品并显示它们。返回的 HTML 包含用户可以在文本框中增加和减少数字值的部分。
当我打开 products.html
页面时,将值增加或减少 1 的按钮最初起作用,但是,当我进入 search.html
并返回到 products.html
时页面使用我的 Android 的后退按钮(我有 pushState = true
)并按 increase/decrease 按钮 increases/decreases 2。如果我再次尝试做同样的事情 increases/decreases 乘以 3 等等……
这是我 products.html 页面中的 increase/decrease 代码:
myApp.onPageAfterAnimation('catalogs', function (page) {
//Increse/decrease product quantity
$(“.promo-screen-content”).on(“click”, “.addToCartBtn”, function(){
var productid = $(this).attr(“data-productId”),
currentvalue = parseInt($('#txtQuantity' + productid).val());
$('#txtQuantity' + productid).val((currentvalue + 1).toString());
});
$(“.promo-screen-content”).on(“click”, “.removeFromCartBtn”, function(){
var productid = $(this).attr(“data-productId”),
currentvalue = parseInt($('#txtQuantity' + productid).val());
if(currentvalue > 1){
$('#txtQuantity' + productid).val((current_value – 1).toString());
}
});
});
有人知道为什么会发生这种情况以及如何解决它吗?
我的第二个问题有点不同。每当我单击一个按钮时,它都会单击并执行该过程 3 或 4 次。因此,例如,如果我在单击时显示通知,它会显示该通知 3 或 4 次。
我不知道这些是否普遍或人们遇到过的问题。非常感谢任何帮助!
我将我的代码放入错误的页面回调中。我不得不把它放在 .onPageInit();
回调中。