【问题标题】:correct syntax for .css element to be added to droppable for html tags.css 元素的正确语法被添加到 html 标签的 droppable
【发布时间】:2019-05-04 20:58:46
【问题描述】:

我使用 jquery 的时间不长。我正在尝试在另一个可放置元素中创建一个可放置元素。

通过嵌套它可以正常工作,但是由于新项目在创建之前没有类,我想在创建期间格式化 CSS 属性。

我正在使用.css{()} 函数,它适用于所有正常格式。 但是,我无法弄清楚将 H1 或 H2 设置为 none 或更改新可放置克隆中的标签的语法。

我尝试将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.

【问题讨论】:

    标签: jquery css jquery-ui


    【解决方案1】:

    嘿,最后一行代码中存在语法问题:

    $(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');
    

    【讨论】:

    • 谢谢。是的,我的朋友也给我发了类似的语法。如果之前没有大量使用过 JqueryUI,很难进入 JqueryUI。我过去常常避免它,只是从头开始编写所有东西,但是很高兴有一种简化的方法来添加不需要几天才能编写的功能。
    • @josephx 没问题多一点项目,你会习惯它:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-06
    • 1970-01-01
    • 2021-11-14
    • 2011-07-05
    • 1970-01-01
    • 2021-12-05
    相关资源
    最近更新 更多