Ose*_*eer 3 javascript variables jquery object
我有:
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);
}
Run Code Online (Sandbox Code Playgroud)
这工作正常.对象及其值已经定义.但是,我有多个以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);
}
Run Code Online (Sandbox Code Playgroud)
当我使用变量作为对象名称时,为什么它会停止工作?