jquery - 如何检查是否支持naturalWidth?

标签 jquery image height width

我有以下 jQuery 并想测试是否支持naturalWidth:

function special(image) {
    if (typeof this.naturalWidth != 'undefined') {
        //do something
    }
}

但这似乎不起作用?有什么想法吗?

最佳答案

试试这个

function special(image) {
    if (image && image.naturalWidth) {
        //do something
    }
}

关于jquery - 如何检查是否支持naturalWidth?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6900177/

相关文章:

javascript - Bootstrap 弹出窗口无法正常工作

html - 创建适合 div 图像高度的水平图像组合?

jquery - 固定高度为 100% 的 Div

c++ - 如何将 QLabel 的大小设置为其像素图中图像的大小?

c# - 通过 RESTful webservice 返回图片

css - 嵌套的 DIV 不服从自动

height - 具有固定高度的 CSS word-wrap/text-overflow

javascript - jQuery 或 JS : Piggyback on post return?

jquery - 使用 jQuery 设置一个等于一堆类的 var,然后隐藏该变量

javascript - 写入服务器: using text file with HTML5 Jquery/Javascript