使用jquery禁用/启用div

时间:2011-12-08 19:24:50

标签: html jquery-mobile

我对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>

我的目标是在开始时禁用id="post"的div,当用户点击“保存”时,我想启用div。我尝试使用$('#post').attr('disabled', true);,但它似乎不起作用。 div不会被禁用 关于如何实现这一点的任何想法。

4 个答案:

答案 0 :(得分:1)

你的意思是禁用div内的输入吗? 我不是jQuery,但我想它应该是:$( "#div > input" ).attr( "disabled" , "true" );

可能没有true声明。

答案 1 :(得分:1)

可能是这样的:http://jsfiddle.net/MTQzD/

文档准备就绪后,禁用#post中的所有输入。也可以在你的css中为#post选择一种颜色(例如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");
});

答案 2 :(得分:0)

此代码适用于我

  

股利

<span id="template_buttons">
  <button class="button">Button 1</button>
  <button class="button">Button 2</button>
  <button class="button">Button 3</button>
</span>
  

禁用所有对象

$("#template_buttons *").attr("disabled", "disabled").off('click');
  

启用所有对象

$("#template_buttons *").attr("disabled", false);

检查jsfiddle http://jsfiddle.net/muthupandiant/orv2d9k1/1/

答案 3 :(得分:0)

$('#div_name:input')。attr('disabled',true); //禁用div输入元素

$('#div_pjt:input')。removeAttr('disabled'); //启用div输入元素

  

此代码适用于我