gpt4 book ai didi

javascript - 在 jQuery 语法中使用 CSS 错误属性名称包含破折号字符

转载 作者:行者123 更新时间:2023-12-01 03:31:09 24 4
gpt4 key购买 nike

我尝试更改图像的样式,直到出现以下情况为止都可以:

There is a dash in 'justify-content' property 's name

$('#pic-upload').css({
display: "flex", //This is OK
justify-content: "center", // This is an error (have a dash in 'justify-content' property 's name)
align-items: "center" // And ofcourse this is also a more error
});

如何解决这个问题?非常感谢!

最佳答案

您可以将属性名称括在引号中:

$('#pic-upload').css({
"justify-content": "center",
"align-items": "center"
});

或者你可以使用驼峰式外壳:

$('#pic-upload').css({
justifyContent: "center",
alignItems: "center"
});

引用: https://api.jquery.com/css/#css2

关于javascript - 在 jQuery 语法中使用 CSS 错误属性名称包含破折号字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59495733/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com