我想更改" invocation_num"的值在循环中,我通过这种方式做到了它给我的不受欢迎的价值任何帮助,请
$(document).on("click", '.favoret', function(){
document.location.href='#favoretList';
var invocation_num = 0;
$('#favoret_table').html('');
itemsDb.transaction(function(transaction) {
transaction.executeSql('SELECT * FROM favoret GROUP BY title_id', [] , function(transaction, results) {
$.each(results.rows, function(key, value) {
var title_count;
for ( var i =0; i < title_obj.length; i++){
if(title_obj[i]['id'] == results.rows.item(key).title_id ){
itemsDb.transaction(function(transaction,invocation_num) {
transaction.executeSql('SELECT * FROM favoret', [], function(transaction, results) {
$.each(results.rows, function(key, value) {
if(title_obj[i]['id'] == results.rows.item(key).title_id){
console.log(results.rows.item(key).title_id);
invocation_num++;
}
});
});
});
$('#favoret_table').append('<tr class="list-row2 go-invoice" id="'+title_obj[i]['id']+'"><td width="100%" class="middle left-border"><span class="black" style="font-family:Nilland; font-size:17px ; font-weight:200;line-height:1rem">'+title_obj[i]['title']+' ('+get_count(title_obj[i]['id'])+') </span></td><td class="middle"><span class="icon arrow orang2"></span></td></tr>');
break;
}
}
});
});
});
// alert(favoret_title);
});
我试图把它放在一个功能中,但它也不起作用
答案 0 :(得分:0)
不要在您的javascript中添加sql
为了回答你的问题,在&#34;窗口定义了一个全局变量&#34;范围。因此,要使变量成为全局变量,只需像这样定义它
window.somevariable = 'value';