Javascript 如何使用Jasny Bootstrap实现图像大小(维度)验证
我正在使用Jasny的引导来显示图像预览并上传它 HTML结构如下所述Javascript 如何使用Jasny Bootstrap实现图像大小(维度)验证,javascript,jquery,twitter-bootstrap,jquery-plugins,jasny-bootstrap,Javascript,Jquery,Twitter Bootstrap,Jquery Plugins,Jasny Bootstrap,我正在使用Jasny的引导来显示图像预览并上传它 HTML结构如下所述 <div class="fileinput fileinput-new" data-provides="fileinput"> <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="display: block; width: 100%; min-height: 150px;"></div>
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-preview thumbnail" data-trigger="fileinput" style="display: block; width: 100%; min-height: 150px;"></div>
<div style="width: 100%;"><label>Min. width: 600px, height: 700px </label></div>
</div>
我试着到处寻求帮助,但没有成功。还有其他办法吗?上述解决方案是:
<script>
var DD=jQuery.noConflict();
function abc(){
DD( "div.fileinput-preview" ).each(function() {
var pDiv=this;
DD(this).on('DOMNodeInserted', function() {
var img = new Image();
img.src = (DD('img', this).attr('src'));
img.onload = function() {
var w=img.width;
var h=img.height;
if(w < 600 || h < 700) {
DD(pDiv).parents('.fileinput').fileinput('clear');
DD(pDiv).parents('.fileinput').find('.min_msg').css("color", "red");
} else {
DD(pDiv).parents('.fileinput').find('.min_msg').css("color", "black");
}
}
})
});
}
DD(function() {
abc();
DD('.blt-add-new-image').on('click', function(){
abc();
})
});
</script>
var DD=jQuery.noConflict();
函数abc(){
DD(“div.fileinput-preview”)。每个(函数(){
var pDiv=此;
DD(this).on('DOMNodeInserted',function(){
var img=新图像();
img.src=(DD('img',this).attr('src');
img.onload=函数(){
var w=img.宽度;
var h=img.高度;
如果(w<600 | h<700){
DD(pDiv).parents('.fileinput').fileinput('clear');
DD(pDiv).parents('.fileinput').find('.min_msg').css(“颜色”,“红色”);
}否则{
DD(pDiv).parents('.fileinput').find('.min_msg').css(“颜色”、“黑色”);
}
}
})
});
}
DD(函数(){
abc();
DD('.blt add new image')。在('click',function()上{
abc();
})
});
可能与@DarrenSweeney重复:我已经编辑了我的问题并添加了更多信息。我认为这不可能重复。你能重新检查一下并帮我找到解决方案吗?
$(function() {
$('.fileinput-preview').on('DOMNodeInserted', function(event) {
var imgdata = ($('.fileinput-preview img').attr('src'));
var h = imgdata.height;
var w = imgdata.width;
console.log(w + ' ' + h);
})
});
<script>
var DD=jQuery.noConflict();
function abc(){
DD( "div.fileinput-preview" ).each(function() {
var pDiv=this;
DD(this).on('DOMNodeInserted', function() {
var img = new Image();
img.src = (DD('img', this).attr('src'));
img.onload = function() {
var w=img.width;
var h=img.height;
if(w < 600 || h < 700) {
DD(pDiv).parents('.fileinput').fileinput('clear');
DD(pDiv).parents('.fileinput').find('.min_msg').css("color", "red");
} else {
DD(pDiv).parents('.fileinput').find('.min_msg').css("color", "black");
}
}
})
});
}
DD(function() {
abc();
DD('.blt-add-new-image').on('click', function(){
abc();
})
});
</script>