我是javascript的新手。如果问题是错误的 我在文件夹中有不同的图像格式。
如何显示所有图像? 下面给出了读取.jpg的代码。我需要包括其他图像格式,如.JPG,.png等..
$ps_albums.children('div').bind('click',function(){
var $elem = $(this);
var index=parseInt($elem.index());
var folder_no=elems-index;
var album_name = 'albums/album' + folder_no;
var j=0;
var dir=album_name;
var d1=album_name+"/";
var fileextension=".JPG";
var f1=".jpg";
var f2=".png";
//var f3=".PNG";
$loading = $('<div />',{className:'loading'});
$elem.append($loading);
$ps_container.find('img').remove();
for(var i = 0; i < 3; i++){
var d=d1+(i+1)+f1;
data1[i]=d;
}
//alert(data1);
var items_count = data1.length;
for(var i = 0; i < items_count; ++i){
var item_source = data1[i];
var cnt = 0;
var img=new Image();
var title=$('span')[index].innerHTML;
$('<img />').load(function(){
var $image = $(this);
++cnt;
resizeCenterImage($image);
$ps_container.append($image);
var r = Math.floor(Math.random()*41)-20;
if(cnt < items_count){
$image.css({
'-moz-transform' :'rotate('+r+'deg)',
'-webkit-transform' :'rotate('+r+'deg)',
'transform' :'rotate('+r+'deg)'
});
}
if(cnt == items_count){
$loading.remove();
$ps_container.show();
$ps_close.show();
$ps_play.show();
//$ps_pause.show();
$ps_overlay.show();
}
}).attr('src',item_source,'title',title);
}
});
此功能用于在单击按钮时显示图像 提前谢谢。
答案 0 :(得分:0)
这可能会有所帮助
//before adding
if(validateImage(currentImage)){
//Add to Data1
}else{
//alert("Only .jpg, .jpeg,.png, .gif files are allowed!");
console.log("Only .jpg, .jpeg,.png, .gif files are allowed!");
}
function validateImage(currentImage) {
//Regular Expression for fileupload control.
var reg = /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.jpg|.jpeg|.png|.gif)$/;
if (currentImage.length > 0) {
//Checks with the control value.
if (reg.test(currentImage)) {
return true;
}
else {
//If the condition not satisfied shows error message.
//alert("Only .jpg, .jpeg,.png, .gif files are allowed!");
return false;
}
}
} //End of function validate.