开发者

Pass parameters into document.ready() calls

I am using a jQuery UI dialog but instead of duplicating the dialog setup 5 times, I was wondering if I can somehow pass the 开发者_开发问答div id as a parameter into the document.ready() call or when I call the div in question?

For example>

$(document).ready(function(){ 

$(function() {
  location.hash = 'PAGETOP';
});

   $("#dialogou").dialog({
            autoOpen: false,
            closeOnEscape: false,
            resizable: false,
            modal: true,
            draggable: true,
            position:  ["center", 100],
            buttons: {
              'Ok': function() {               
                      $(this).dialog("close"); 
                      closeReq();
                    }
        }
    });  
 });

So based on the above, if I have the following if condition:

  if (document.getelementbyId("ERROR_OU").value == "Y")
    $('#dialogou').dialog('open');

I would like to be able to change the div id dilaogou to dialogao but still use the same call above but obviously swap out dilaogou to dilaogao.

Is this possible?


Just make a selector that matches any of the id:s when doing the initialization:

$("#dialogou, #dialogao, #dialogxx, #dialogyy, #dialogzz").dialog({
...

Now you have the dialog set up for all the elements, and you can call dialog('open') on any of them.


How about using an array:

$(document).ready(function(){ 

var dialog_ids=['dialogou', 'dialaogao'];

$(function() {
  location.hash = 'PAGETOP';
});

for(id in dialog_ids)
{
       $("#"+dialog_ids[id]).dialog({
                autoOpen: false,
                closeOnEscape: false,
                resizable: false,
                modal: true,
                draggable: true,
                position:  ["center", 100],
                buttons: {
                  'Ok': function() {               
                          $(this).dialog("close"); 
                          closeReq();
                        }
            }
        });  
     });
 }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜