Html 使用 jquery 禁用/启用 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8436468/
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
Disabling/Enabling div using jquery
提问by Hozefa
I am relatively new to jQuery. I am working on an application to create a widget for accepting donations for NGO.
我对 jQuery 比较陌生。我正在开发一个应用程序来创建一个用于接受非政府组织捐赠的小部件。
<div data-rle="content" id="save">
<label for="saveWidget">Save your Widget before posting in online:</label>
<input type="submit" value="Save Widget" id="saveWidget"
data-theme="b" data-inline="true" />
</div>
<div data-rle="content" id="post">
<fieldset data-role="controlgroup">
<legend>Select on option for posting your online:</legend>
<input type="radio" name="submit" id="html" value="hmtl"
checked="checked" /> <label for="html">Please provide
the HTML - I'll post it myself. <br>The HTML will be
displayed below.</label>
<input type="radio" name="submit" id="blog" value="blog" /> <label
for="blog">Go to Blogger</label>
</fieldset>
<input type="submit" value="Get HTML" id="submitWidget"
data-theme="b" data-inline="true" />
</div>
My goal is to have the div with id="post"
disabled in the start, and when user clicks on save I want to enable the div. I tried using $('#post').attr('disabled', true);
but it does not seem to work. The div does not get disabled
Any ideas on how to achieve this.
我的目标是id="post"
在开始时禁用div ,当用户单击保存时,我想启用 div。我尝试使用$('#post').attr('disabled', true);
但它似乎不起作用。div 不会被禁用 关于如何实现这一点的任何想法。
回答by Michael Sazonov
Do you mean disabling the inputs inside the div?
I'm not into jQuery, but I guess it should be like: $( "#div > input" ).attr( "disabled" , "true" );
.
你的意思是禁用div内的输入?我不喜欢 jQuery,但我想它应该是这样的: $( "#div > input" ).attr( "disabled" , "true" );
.
Maybe without the true
statement.
也许没有true
声明。
回答by CdB
maybe something like this: http://jsfiddle.net/MTQzD/?
也许是这样的:http: //jsfiddle.net/MTQzD/?
When document is ready disable all inputs in #post
. Also give #post a color of your choice in your css (e.g. lightGray).
Then when "Save Widget" is clicked, enable the inputs and remove the color of the #post div.
当文档准备好时,禁用#post
. 还要给#post 在你的css 中选择你喜欢的颜色(例如lightGray)。
然后,当单击“保存小部件”时,启用输入并删除 #post div 的颜色。
$(document).ready(function() {
$('input[type=radio]').attr('disabled', true);
$('#submitWidget').attr('disabled', true);
});
$("#saveWidget").click(function() {
$('input[type=radio]').attr('disabled', false);
$('#submitWidget').attr('disabled', false);
$('#post').css("background-color", "#EAEAEA");
});
回答by muTheTechie
This code works for me
这段代码对我有用
Div
分区
<span id="template_buttons">
<button class="button">Button 1</button>
<button class="button">Button 2</button>
<button class="button">Button 3</button>
</span>
For disable all objects
禁用所有对象
$("#template_buttons *").attr("disabled", "disabled").off('click');
For Enable all objects
对于启用所有对象
$("#template_buttons *").attr("disabled", false);
Check in jsfiddle http://jsfiddle.net/muthupandiant/orv2d9k1/1/
签入 jsfiddle http://jsfiddle.net/muthupdiant/orv2d9k1/1/
回答by user6467624
$('#div_name :input').attr('disabled', true);//disable div input elements
$('#div_name :input').attr('disabled', true); //禁用div输入元素
$('#div_pjt :input').removeAttr('disabled');// enable div input elements
$('#div_pjt :input').removeAttr('disabled'); // 启用 div 输入元素
This code works for me
这段代码对我有用