if (!myObj.login_id) {
alert("The object for login_id does not exist.");
} else {
alert("The object for login_id DOES exist. The value of the object is: " + myObj.login_id);
}
這是正常工作。對象和它的值已經被定義了。但是,我有多個對象,它們的ID都是以attr命名的。所以,我嘗試這樣做(例如說這是一個點擊事件:?
objtitle = $(this).attr('id'); // this is "login_id"
if (!myObj.objtitle) {
alert("The object for "+objtitle+" does not exist.");
} else {
alert("The object for "+objtitle+" DOES exist. The value of the object is: " + myObj.objtitle);
}
爲什麼它停止工作時,我使用一個變量爲對象的名稱
'if(!myObj [this.id]){...' –