jquery - 将 .css 元素添加到 html 标签的 droppable 的正确语法

标签 jquery css jquery-ui

我使用 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/

相关文章:

使用 ajax 的 jQuery UI 自动完成,其源是使用 foreach 从文本文件生成的

javascript - 拖入 gridster 之前的延迟

jquery - 如何按字母顺序对 JQuery UI 可排序进行排序?

javascript - 在 Chrome 中将光标属性重置为 "grab"不起作用

javascript - 使用全日历在内容窗口上保持弹出窗口打开

background-image - 具有水平渐变的 CSS 背景图像

html - 最大化单元格宽度的 CSS 表格属性

jquery - 获取表中非隐藏行的数量

jquery - 在 jQuery 中组合键码事件

javascript - 根据指定的数据属性隐藏元素