jQuery create new div with ID?

后端 未结 4 544
栀梦
栀梦 2021-01-22 03:29

I have form in my ASP.NET masterPage.master and if i click on submit it call some method from masterPage.master.cs file by ajax (i have it in update panel). But i want improve i

4条回答
  •  天命终不由人
    2021-01-22 04:08

    I like to create the element this way:

        $('
    ',{ id: 'idhere', css:{ width: $('#formBox').width(), height: $('#formBox').height() } });

    etc...

    For reference - some attributes have reserved words/names (see MDN Reserved Words), so if you wanted to specify a class you need to wrap the attribute name:

            $('
    ',{ id: 'idhere', 'class':'myclassname', css:{ width: $('#formBox').width(), height: $('#formBox').height() } });

    You can of course assign a name to this new element and change it as you go along...

    var div = $('
    ',{ id: 'idhere', 'class':'myclassname', css:{ width: $('#formBox').width(), height: $('#formBox').height() } }); $(div).prop('name','saymyname');

提交回复
热议问题