选择不工作从AJAX调用元素元素、工作、AJAX

2023-09-10 20:58:38 作者:每个想念都关于你。

我有填充的基础上使用AJAX调用一个选择框选择div元素的一种形式。

I have a form which populates div elements based on selections from a select box using an AJAX call.

在填充div的内容是,我要选择适用于多选框。不幸的是,似乎chzn,选择不点火,毫无疑问,因为这被动态地被拉研究。

The content of the populated div is a multiselect box that I want Chosen to apply to. Unfortunately it seems that the 'chzn-select' is not firing, no doubt due to this being pulled in dynamically.

我添加了这一点:

    <script type="text/javascript">
    $(".chzn-select").chosen();
    </script>

要的是由AJAX拉在code底部,但它仍然是不点火。如何根据需要使这项工作任何想法?

To the bottom of the code that is pulled in by AJAX, but it is still not firing. Any ideas on how to make this work as desired?

推荐答案

解决自己。将发布以供将来参考。我把自己的功能已选择呼叫我调用AJAX原始页面:

Solved myself. Will post for future reference. I put the Chosen calls in their own function on my original page that calls the AJAX:

    <script type="text/javascript">
    function doChosen() {
        $(".chzn-select").chosen();
        $(".chzn-select-deselect").chosen({allow_single_deselect:true});
    }
    </script>

而在AJAX脚本本身,我添加了一个调用该函数的responseText的部分之后:

And in the AJAX script itself, I added a call to the function after the responseText part:

    document.getElementById(div).innerHTML=oXmlHttp.responseText
    doChosen();
 
精彩推荐
图片推荐