为每个评论分别按自己的 id 预览图像
Preview image by its own id separately for each comment
在我的评论上传图像系统中,它的浏览图像并显示它。如果我浏览评论中的图像,它还会显示所有其他评论的显示字段。是否可以按自己的$id仅显示浏览图像。
(注意注释字段按其自己的$id显示/隐藏,此处删除以供使用)
这是我的工作 http://jsfiddle.net/er9e72ww/2/
我的预览图像脚本是:
//preview image
$(".repfile").change(function(){
previewPic(this);
});
function previewPic(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$(".preview_rep").attr('src', e.target.result);
$(".output_rep").show();
$(".replycom").focus();
$('#img').hide();
};
reader.readAsDataURL(input.files[0]);
}
}
和 php 上传表单:
<div align="left" id="show_img_upload_rep" class="show_img_upload_rep" style="padding-top:5px; display:none">
<div class="upfrmrep" >
<div class="output_rep" style="display:none;">
<img class="preview_rep" src="" alt="No Image Found"/>
</div>
<form action="uploadpostimg.php" class="upload_Reply" method="post" enctype="multipart/form-data">
<label for="file" style="font-size:12px;font-weight:bold;">Filename (Max 200 Kb) : </label>
<input type="file" name="file" class="repfile" id="'.$id.'" value=""/>
<img class="loading" src="loader.gif" alt="" style="margin:5px;display:none;"/>
<input type="submit" class="upload_file" name="upload_btn" value="Upload Picture"/>
</form>
</div></div>
现在我想为每个预览使用一个$id,如下所示:
.php
//Preview want to Add '.$id.'
<div class="output_rep'.$id.'" style="display:none;">
<img class="preview_rep'.$id.'" src="" alt="No Image Found"/>
</div>
我尝试的脚本(可能是错误的)不起作用
//preview image
$(".repfile").change(function(){
var ID = $(this).attr('id').replace('','');
previewPic(this);
});
function previewPic(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$(".preview_rep"+ID).attr('src', e.target.result);
$(".output_rep"+ID).show();
$(".replycom").focus();
$('#img').hide();
};
reader.readAsDataURL(input.files[0]);
}
}
由于我将元素传递给另一个函数,因此我可以从那里获取 ID。无需在更改处理程序中获取 ID。
删除:
var ID = $(this).attr('id').replace('','');
改变:
$(".preview_rep"+ID).attr('src', e.target.result);
$(".output_rep"+ID).show();
自:
$(".preview_rep" + input.id).attr('src', e.target.result);
$(".output_rep" + input.id).show();
相关文章:
- 按我自己的类克隆另一个元素的内容和顺序
- Javascript-ID冲突的几率
- 如何配置分析以将数据发送到我自己的服务器
- 如何使用jquery ajax和jsonp在您自己的域上读取json数据
- 创造自己的智能
- 如何在Win8Metro应用程序的Javascript代码中捕获自己的C#事件
- 从自己的安全系统中重新找回自己
- ID为的HTML样式类
- 如何使用jQuery迭代id名称的变体(如idname1、idname2)
- 麻烦将coffee脚本片段移动到rails中自己的类中
- 如何编写用于id验证的正则表达式(JavaScript)
- 从我自己的脚本中包含的Javascript文件中调用一个函数
- 让我自己的过滤器不工作
- 消隐数组元素是否生成自己的属性
- JavaScript子对象访问自己的值
- Selenium异步脚本在自己的线程中阻塞其他脚本
- 为什么对象的函数值没有自己的作用域
- 为每个评论分别按自己的 id 预览图像
- 命名我自己的firebase唯一ID/Keys.Javascript
- 我如何使用backbone集合解析方法在每个模型上设置自己的id