我使用 jquery 的时间不长。我正在尝试在另一个可放置元素中创建一个可放置元素。
通过嵌套它工作正常,但由于新元素在创建之前没有类,我想在创建期间格式化 CSS 属性。
我正在使用 .css{()}
函数,它适用于所有正常格式。
然而,我无法弄清楚将 H1 或 H2 设置为无或在新的可放置克隆中更改标签的语法。
我尝试将 h2 {display: 'none'}
添加为一行,但它不接受该格式。
//It is the bottom line of code, but this is to show how it is nested
//which is why I am trying to set the css this way.
drop: function (event, ui) {
$(this)
.append(ui.helper.clone(false)
.css({
position: 'relative',
left: '0px',
top: '0px',
height: "75px",
width: "100%"
})
.droppable({
accept: "#gallery > li",
classes: {
"ui-droppable-active": "ui-state-highlight"
},
drop: function (event, ui) {
$(this)
.append(ui.helper.clone(false)
.css({
position: 'relative',
display: 'inline-block',
padding: '1%',
left: '0px',
top: '0px',
height: "36px",
width: "auto",
h2 {display: 'none'} //right here is the problem.
最佳答案
你好,最后一行代码有语法问题:
$(this)
.append(ui.helper.clone(false)
.css({
position: 'relative',
display: 'inline-block',
padding: '1%',
left: '0px',
top: '0px',
height: "36px",
width: "auto"});//Here you should close your style
//Maybe here you mean to find the H2 element who is a child of this element then
.find('h2').css('display','none');
关于jquery - 将 .css 元素添加到 html 标签的 droppable 的正确语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55986739/