在原型.js中设置原型值失败
Set Value with prototype fails inside prototype.js
我有一个原型.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('<input type="hidden" value="" name="">');
jQuery('#fileThumb').prepend('<img id="uploaded_img" src="theImg.png"/>');
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。怎么了,有什么想法吗?
编辑:网页部分
<form id="file_upload_form" class="form-horizontal" method="post" enctype="multipart/form-data" action="ajax/user_photo_upload.ajax.php">
<h3 class="form-section map_header"><img src="_themes/1/img/map_photo_upload.png"> <?=$core->l("photo_upload");?></h3>
<div class="row-fluid">
<div class="span12">
<div class="control-group">
<label class="control-label">
<i class="icon-eye-open"></i>
<?=$core->l("upload_select_image")?>
<span class="formRequiredElement">*</span>
</label>
<div class="controls">
<div class="fileupload fileupload-new" data-provides="fileupload" data-name="myimage" id="fileDiv" >
<input type="hidden" value="1" name="myimage">
<div class="fileupload-new thumbnail" style="width: 200px; height: 150px;">
<img src="_themes/images/no_image.gif" id ="photo"/>
</div>
<div class="fileupload-preview fileupload-exists thumbnail" id ="fileThumb" style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>
<div class="photoUploadAlign">
<span class="btn btn-file btn green"><span class="fileupload-new"><?=$core->l("select_image")?></span>
<span class="fileupload-exists" id="change_clicked"><?=$core->l("change_image")?></span>
<input type="file" class="default" name="file" id="file"></span>
<a href="#" class="btn fileupload-exists btn red" data-dismiss="fileupload" id="remove_clicked"><?=$core->l("remove_image")?></a>
</div>
</div>
<span class="label label-important"><?=$core->l("warning")?></span>
<span><?=$core->l("warning_note")?></span>
<iframe id="upload_target" name="upload_target" src="" style="display:none;width:0;height:0;border:0px solid #fff;"></iframe>
<input type="reset" id="clearFields" style="display:none"/>
</div>
</div>
</div>
</div>
</form>
好吧,我已经找到了解决方案,我在这里写,以防其他面临此问题的人看到,
改变
beforeEditorButtonClick: function(browser, toolType) {
switch (toolType) {
case browser.BUTTON_SAVE:
if (UserEditor.newPhoto == "1") {
this.UserPhotoUploadEditor.uploadFile();
return false;
}
}
return true;
},
和原型类之后:
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";
});
解决了问题。
相关文章:
- 使用“;这个“;JavaScript原型方法中的关键字
- 引用类变量中的原型方法
- 如何从对象的原型方法访问JavaScript对象属性
- 为什么要包装每一个原型“;类“;JS中具有匿名函数的对象
- 当json解析空响应时,Whatwg-Fetch失败,我该如何防止它
- JsFiddle在分叉后描述失败
- Node.js中的JavaScript原型对象效率
- 重载JS'firefox中的对象原型
- “util.inherits”和在NodeJS中扩展原型之间的区别
- 附加到原型属性的Do函数没有闭包
- 在原型.js中设置原型值失败
- Javascript 原型函数失败
- 为什么这个Javascript原型代码失败了
- 为什么这个原型失败了
- JavaScript继承(将原型设置为内部)失败
- jQuery'原型部分继承失败
- obj.如果在ExtJs类原型中定义了构造函数,则get函数失败
- 试图删除HTMLElement的原型失败
- 由于将比较方法添加到数组原型而导致测试失败.如何更新代码或测试?
- 将Javascript命名空间闭包和原型一起使用会失败