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]){...' –