jQuery - Animation for Enabled/Disabled Textboxes

。_饼干妹妹 提交于 2020-01-06 07:03:10

问题


I have a simple form with some disabled text boxes. When the user clicks on the checkbox, the textboxs are enabled.

How can i add some animation on the textboxes so that when the checkbox is checked, the boxes fade in or slide in..

HTML:

<ul>
<li>
    <input id="addPreviousAddress" name="addPreviousAddress" type="checkbox" />
    <label class="blueText boldText" for="addPreviousAddress">Add Previous Address</label>
</li>
<li>
    <label>House Number</label>
    <input class="requiredField" id="prevHouseNumber" size="10" Maxlength="10" disabled="" type="text" />&nbsp
    <label>Flat Number</label>
    <input class="one-sixth requiredField" id="prevFlat" size="10" Maxlength="16" disabled="" type="text" />
</li>
<li>
    <label>House Name</label>
    <input id="prevHouseName" size="24" Maxlength="26" disabled="" type="text" />
</li>
<li>
    <label>Street</label>
    <input class="three-fifths requiredField" id="prevStreet" size="40" Maxlength="40" disabled="" type="text" />
</li>
<li>
    <label>Town</label>
    <input class="three-fifths" id="prevTown" size="40" Maxlength="20" disabled="" type="text" />
</li>
<li>
    <label>County</label>
    <input class="three-fifths" id="prevCounty" size="25" Maxlength="20" disabled="" type="text" />
</li>
<li>
    <label>Postcode</label>
    <input class="requiredField" id="prevPostcode" size="10" Maxlength="8" disabled="" type="text" />
</li>
<li>
    <label>Time at address</label>
    <input type="text" id="prevTimeYY" size="2" Maxlength="2" disabled="" type="text" />Years &nbsp&nbsp&nbsp
    <input type="text" id="prevTimeMM" size="2" Maxlength="2" disabled="" type="text" />Months</li>

JS:

$('#addPreviousAddress').change(function () {

$("#prevHouseNumber").prop("disabled", !$(this).is(':checked'));
$("#prevFlat").prop("disabled", !$(this).is(':checked'));
$("#prevHouseName").prop("disabled", !$(this).is(':checked'));
$("#prevStreet").prop("disabled", !$(this).is(':checked'));
$("#prevDistrict").prop("disabled", !$(this).is(':checked'));
$("#prevTown").prop("disabled", !$(this).is(':checked'));
$("#prevCounty").prop("disabled", !$(this).is(':checked'));
$("#prevPostcode").prop("disabled", !$(this).is(':checked'));
$("#prevTimeYY").prop("disabled", !$(this).is(':checked'));
$("#prevTimeMM").prop("disabled", !$(this).is(':checked'));

});

Here's my fiddle: http://jsfiddle.net/oampz/mtsZ9/1/

Any help would be appreciated.


回答1:


Try this code:

DEMO

  $('#addPreviousAddress').change(function () {
     $("input").not(this).hide();
     $("input").not(this).prop("disabled",!$(this).is(':checked')).fadeIn();
  });



回答2:


You can't, because they are already visible. You cannot fade in a visible object. What you can do is, instead of showing those disabled textboxes, you can hide them. Then with the checkbox click, you can fade them in like:

$("#prevHouseNumber").fadeIn();



回答3:


I am not sure if this is want you wanted, but you can try following code:

  $("#prevHouseName").toggle(600,function(){ 
    $(this).prop("disabled", !$(this).is(':checked'))
 });


来源:https://stackoverflow.com/questions/21599059/jquery-animation-for-enabled-disabled-textboxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!