[英]Migrating from jQuery 1 to jQuery 3
我购买了一个 HTML 模板,却发现它使用了 jQuery 1。我正在尝试升级到 jQuery 3,但我在模板的 main.js 文件中遇到了这段代码的问题:
var background_image = function() {
$("[data-bg-img]").each(function() {
var attr = $(this).attr('data-bg-img');
if (typeof attr !== typeof undefined && attr !== false && attr !== "") {
$(this).css('background-image', 'url('+attr+')');
}
});
};
这个引用的 HTML 部分是:
<figure class="deal-thumbnail embed-responsive embed-responsive-16by9" data-bg-img="'.$dealimage.'">
这在升级到 jQuery 3.4.1 时停止工作。 不知道该怎么办。
CSS:
*[data-bg-img] {
background-position: center;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
结果我忽略了最基本的 document.ready 函数,这意味着脚本甚至没有运行。 在 jQuery 1.xx 中它被写成:
$(document).on('ready', function() {
})
我把它改成:
$(document).ready(function() {
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.