javascript - 隐藏按钮,直到我们上传图片或文本

标签 javascript jquery css

我们在 page 中有一个按钮“保存设计”我们还可以选择在页面中上传图片或文本。 在用户上传图片或添加文字之前,我们不想显示“保存设计”按钮

enter image description here

我们使用下面的代码来“保存设计”

_getControlPanelHtml: function()
    {
        if (this.config.editorEnabled) {
            return '<div id="aitcg-control-panel">' +
                '<button id="submit-editorApply-{{rand}}" >SAVE DESIGN</button>' +
                '<button >Reset</button>' +
                '</div>';
        }
        return '';
    },


    initObservers: function()
    {
        if (this.config.editorEnabled) {
            $('submit-editorApply-' + this.config.rand).observe('click', this.submitApply.bindAsEventListener(this));
            $('submit-editorReset-' + this.config.rand).observe('click', this.submitReset.bindAsEventListener(this));
        }
    },

    submitApply: function(event)
    {
        Event.stop(event);
        this.option.apply();
    },

我尝试用下面的代码隐藏“保存设计”,直到我们上传图片或文本。 我关注了这个link我添加了 style="display: none; 然后使用了 show() jQuery 方法。

<script>
    $('submit-editorApply-').show();
    _getControlPanelHtml: function()
    {
        if (this.config.editorEnabled) {
            return '<div id="aitcg-control-panel">' +
                '<button id="submit-editorApply-{{rand}}" style="display:none;" >SAVE DESIGN</button>' +
                '<button >Reset</button>' +
                '</div>';
        }
        return '';
    },

</script>

最佳答案

将事件监听器附加到这两个输入字段,然后检查该字段是否已填充。只有这样你才能使用 $('#submit-editorApply-').show();

例子:

$('#upload_field').on('change', function(){
    if($(this).val() !== ""){
        $('#submit-editorApply-').show();
    }
});

关于javascript - 隐藏按钮,直到我们上传图片或文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43049792/

相关文章:

javascript - 如何停止正在运行的倒计时器?

javascript - 为 div 创建线性透明渐变

javascript - 如何在使用 jquery/css 删除隐藏 div 后按顺序移动 div "up"

html - 我如何将两条 HTML 伪元素线与另一条垂直伪线连接起来,跨越表格行?

javascript - 切换后菜单消失

javascript - 错误 : Cannot find module 'config' at Function. Module._resolveFilename

javascript - Javascript 函数问题

Javascript 和 Canvas : Endless random animation of slightly morphing circle?

php - 如何在 foreach 循环中回显消息一次

html - 揭开 Logo - 被另一个 DIV 的背景图像阻止