html标签属性“data-setbg"在 React 项目中不起作用 [英] html tag attribute "data-setbg" is not working in React project

查看:61
本文介绍了html标签属性“data-setbg"在 React 项目中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 HTML 网站模板 转换为 React 项目,在该模板中有一个名为 data-setbg 的属性,但是没有提供标准的 html 属性,我想知道什么样的库或框架提供了这种设置 HTML 元素背景图像的能力?

I'm converting a HTML website template into a React project, in that template there is an attribute called data-setbg, but there is no standard html attribute provided, I wonder what kind of library or framework provide this ability to set HTML's element background image like that?

推荐答案

原来作者是使用 JavaScript 来做一个捷径和简单的方法来将元素背景设置为图像,我在里面找到了这个 .js 代码模板:

it turns out the writer is using JavaScript to do a short cut and easy way for setting up the element background as image, I found this .js code within the templates:

    $('.set-bg').each(function() {
        var bg = $(this).data('setbg');
        $(this).css('background-image', 'url(' + bg + ')');
    });

这篇关于html标签属性“data-setbg"在 React 项目中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆