5

So I'm trying to apply the Chosen jQuery plugin to a select box after it has been loaded via XAJAX. Here's the code:

Normally, I start on page load, and all select boxes with the class are correctly styled appropriately:

$(document).ready( function () {        
    $(".chzn-select").chosen();
});

Next, I have a function that uses XAJAX to display the new select box in the specified DIV on the page. This works fine. HOWEVER, it's not styled by Chosen as it should be.

I have tried to add a delay in there too, because I read on some forums that that worked for some people. It does not work....

function getNewSelect(property_id){
    xajax_getNewSelect();
    $(".chzn-select-ajax").delay(5).chosen();
}

Does anyone have any ideas?

4

2 回答 2

4

What does xajax do?

delay only delays animations, it has no effect on any other function.

If you want to delay a function use:

setTimeout(function() { $(".chzn-select-ajax").chosen(); }, 500);
于 2012-08-31T01:24:16.280 回答
1
<script language="javascript" type="text/javascript">
    $(function () {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(loadControlDuringAjax);
        loadControlDuringAjax();
    });
    function loadControlDuringAjax() {
        $(".chzn-select").chosen(); $(".chzn-select-deselect").chosen({ allow_single_deselect: true });
    }
</script>

这对我很有用

希望这能解决你的问题

于 2012-09-06T09:00:54.317 回答