选择不工作从AJAX调用元素 [英] Chosen not working on elements from AJAX call

查看:108
本文介绍了选择不工作从AJAX调用元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有填充的基础上使用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();

这篇关于选择不工作从AJAX调用元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆