所以,我正在检查localStorage以查看是否存在某个键,如果存在,则更改按钮值。
with open('test_items.csv', 'r') as plik:
tab = {}
for line in plik:
line = line.split(',')
tab[line[0]] = line[1:]
with open('pin_items.csv', 'r') as plik1:
for line in plik1:
line = line.split(',')
match = str([i for i in tab.keys() if line[0] in i][0])
if match:
tab[match] = tab[match].append(line[1:])
当我点击按钮时,第一次没有任何反应,只有当我第二次点击它时。
$(document).ready(function() {
console.log(localStorage.length);
ProductName = $("#ProductNameHidden").text();
for (var i = 0; i < localStorage.length; i++) {
if (localStorage.key(i) == ProductName) {
document.getElementById("SubmitButton").value = "GO TO CART";
return false;
} else {
document.getElementById("SubmitButton").value = "ADD TO CART";
}
}
});
答案 0 :(得分:3)
应该是,
$("#SubmitButton").click(function() {
if ($(this).val() == "GO TO CART") {
window.location.href = "Cart.html"
}
});