在prototype.js中,原型设置值失败

我有一个这样的prototype.js类:

UserEditor = Class.create({ dataEditorDisplayed: function(editor) { this.UserPhotoUploadEditor.clearFields(); $(idatabase.FIELD_SITE_ID).instance.disable(); $(idatabase.FIELD_CHANGE_PASSWORD).instance.enable(); this.photoName = this.photoUrl.getValue(); if (this.photoName == null || this.photoName == "") { this.photoName = this.DEFAULT_PHOTO; this.newPhoto = "1"; } else { jQuery("#fileDiv").removeClass("fileupload-new").addClass("fileupload-exists"); jQuery('#fileDiv').prepend(''); jQuery('#fileThumb').prepend(''); jQuery("#uploaded_img").attr("src",this.UPLOADS + this.photoName); this.newPhoto = "0"; } }, beforeEditorButtonClick: function(browser, toolType) { switch (toolType) { case browser.BUTTON_SAVE: if (this.newPhoto == "1") { this.UserPhotoUploadEditor.uploadFile(); return false; } } return true; }, }); jQuery('#change_clicked').on('click',function(){ UserEditor.newPhoto.val("1"); }); 

我要做的是,如果用户按下带有change_clicked id的按钮,我想在switch语句之前设置this.newPhoto = "1" 。 但每次我尝试它总是0.什么是错的,任何想法?

编辑:HTML PART

 

l("photo_upload");?>

l("select_image")?> l("change_image")?> l("remove_image")?>
l("warning")?> l("warning_note")?>

好吧,我找到了解决方案,我正在写这里以防其他人遇到这个问题,

更改

 beforeEditorButtonClick: function(browser, toolType) { switch (toolType) { case browser.BUTTON_SAVE: if (UserEditor.newPhoto == "1") { this.UserPhotoUploadEditor.uploadFile(); return false; } } return true; }, 

并在Prototype类之后:

 UserEditor.newPhoto = "0"; jQuery('#change_clicked').on('click',function(){ UserEditor.newPhoto = "1"; }); jQuery('#remove_clicked').on('click',function(){ UserEditor.newPhoto = "1"; }); jQuery('#select_clicked').on('click',function(){ UserEditor.newPhoto = "1"; }); 

解决问题。