0
我有一個全局變量,通過document.ready()在頁面加載時賦值,但是當我從事件方法訪問它時,它變爲空。javascript全局變量在使用後變爲空
因此,爲了檢查變量是否被賦值,我在賦值後立即添加了一個alert(variable.length),它顯示了期望值,但是當我在事件觸發方法中做同樣的事情時,值是始終爲0
這是我做了什麼
的document.ready()
var selectedCategory = new Array();
$(document).ready(function() {
selectedCategory = $("#<%=hfdGenreList.ClientID%>").val().split(',');
alert(selectedCategory.length);
});
強大的文本
function moveToTextbox() {
alert(selectedCategory.length);
// some code
}
你能提供的jsfiddle? – Grundy 2014-08-31 08:25:36
適合我:http://jsfiddle.net/u2o81d7w/ – Rhumborl 2014-08-31 08:36:13