jquery mobile 无法隐藏提交按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7053335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery mobile cannot hide submit button
提问by Satch3000
I am using the latest version of jquery mobile and my problem is that I have given a submit button an ID and then added some css to set the ID to display:none;
我正在使用最新版本的 jquery mobile,我的问题是我给了一个提交按钮一个 ID,然后添加了一些 css 以将 ID 设置为 display:none;
For some reason this does not work.
出于某种原因,这不起作用。
Has anyone had this problem before?
以前有人遇到过这个问题吗?
采纳答案by no.good.at.coding
It's hard to tell what you're trying to do without any code but I think the problem stems from the fact that jQuery Mobile doesn't style your existing button but rather, hides the element and wraps it in a new div
which is styled to look and behave like a button.
如果没有任何代码,很难说出您想要做什么,但我认为问题源于这样一个事实,即 jQuery Mobile 不会为您现有的按钮设置样式,而是隐藏元素并将其包装在一个新div
的样式中并表现得像一个按钮。
The current jQuery Mobile markup for a button looks like this:
按钮的当前 jQuery Mobile 标记如下所示:
<div data-theme="e" class="ui-btn ui-btn-inline ui-btn-corner-all ui-shadow ui-btn-hover-e ui-btn-down-e" aria-disabled="false">
<span class="ui-btn-inner ui-btn-corner-all">
<span class="ui-btn-text">Submit</span>
</span>
<input type="submit" id="submit_btn" value="Submit" data-theme="e" data-inline="true" class="ui-btn-hidden" aria-disabled="false">
</div>
So you look for the closest ancestor with the class ui-btn
and hide it:
因此,您寻找与该类最接近的祖先并将其ui-btn
隐藏:
$('#submit_btn').closest('.ui-btn').hide();
If there's a better way to do this, I'd love to know about it. Here's a fiddlethat shows my solution in action.
如果有更好的方法来做到这一点,我很想知道。这是一个小提琴,显示了我的解决方案。
回答by greencustard
I always use:
我总是使用:
$("#<button-id>").parent().hide();
It seems to work fine as the button or input element will always be a child of the 'wrapper' div.
它似乎工作正常,因为按钮或输入元素将始终是 'wrapper' div 的子元素。
回答by eric.itzhak
I've had issues with the above answers in cases i needed to toggle between the states.
如果我需要在状态之间切换,我对上述答案有疑问。
I found it easiest to wrap your initial button in a div and then just hide/show it.
我发现将初始按钮包装在 div 中然后隐藏/显示它是最简单的。
Meaning :
意义 :
<div id="someid">
<input type="button" class="submit_button" id="resend_invoice" value="Button"/>
</div>
And then simply addressing the containing div would work as usual, as all the jQuery mobile divs and classes are created inside the containing div.
然后简单地处理包含的 div 会像往常一样工作,因为所有的 jQuery 移动 div 和类都是在包含的 div 中创建的。
回答by aleith
If you add data-role="none"
to your input element, then jQuery mobile will not draw the extra button.
如果添加data-role="none"
到输入元素,jQuery mobile 将不会绘制额外的按钮。