开发者

Add css class after the elements are created from a JS script

I have a div

 <div id="form"/>

Some JS is building up a form from this div.

The result looks like

 <div id="form"> 
     <fieldset>
             ..inputs
     </fieldset>
     <fieldset>
      开发者_运维技巧       ..inputs
     </fieldset>
     <fieldset>
             ..inputs
     </fieldset> 
 </div>

Once the form has been build up I need to run this scripts

$(":input","fieldset:eq(2)").addClass("readonly-form");
$(":input","fieldset:eq(2)").removeClass("txt_textarea");

The problem is when I put these scripts behind to code which is building up the form, the fieldset has not been build yet.

I cannot add attach a class to the fieldset in the JS code,which is building up the form.

Is there any way to wait until the form is build up and then add and remove the css ?

This isn't working

  $(function(){
        var form = new Form("@Model.Name");
        form.AdditionalConfigUrlParams += "isshow=uloha"
        form.Create(@Html.Raw(Model.Data));

        $(":input","fieldset:eq(2)").addClass("readonly-form");
        $(":input","fieldset:eq(2)").removeClass("dhxlist_txt_textarea");

    });


if your form creator had as a complete event you could put it in there otherwise you might want to look at livequery plugin

    $('form').livequery(function() {
        $(":input","fieldset:eq(2)").addClass("readonly-form");
         $(":input","fieldset:eq(2)").removeClass("txt_textarea");
   }


Your jQuery selectors are not right. It should be:

$(":input, fieldset:eq(2)").addClass("readonly-form");// removed quotes between selectors
$(":input, fieldset:eq(2)").removeClass("txt_textarea");// same here

Also this will only select last fieldset.


u can check that form has been created or not

var formReady=form.create(@Html.Raw(Model.Data); // IDK what plugin you r using to create a form
if(formReady) {
 $(":input,fieldset:eq(2)").addClass("readonly-form").removeClass("dhxlist_txt_textarea");
}

or try @mcgrailm method


i think you can use

$(document).ready(function(){
    $(":input","fieldset:eq(2)").addClass("readonly-form");
    $(":input","fieldset:eq(2)").removeClass("txt_textarea");
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜