Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将类应用于jQuery ajax调用的结果?_Php_Jquery_Css_Ajax - Fatal编程技术网

Php 如何将类应用于jQuery ajax调用的结果?

Php 如何将类应用于jQuery ajax调用的结果?,php,jquery,css,ajax,Php,Jquery,Css,Ajax,我试图找到一个答案,但没有成功 我有以下代码: jQuery("#categories_parent_id").change(function() { id = jQuery("#categories_parent_id").val(); jQuery.ajax({ type: "GET", url: 'index.php?option=com_jomdirectory&tas

我试图找到一个答案,但没有成功

我有以下代码:

jQuery("#categories_parent_id").change(function() {
            id = jQuery("#categories_parent_id").val();
            jQuery.ajax({
                type: "GET",
                url: 'index.php?option=com_jomdirectory&task=getselect&format=raw',
                dataType: "html",
                data: "id=" + id,
                success: function(data) {
                    jQuery('#selectlist').html(data);
                }
            });
        });
ajax结果选择应该有类formcontrol和select,我尝试将它们添加到ajax视图中,但它没有样式

在ajax结果之后,我将如何将相关类添加到特定的select中

谢谢


J

稍后编辑,正如@A.Wolff提到的,您需要在新添加的select元素上调用插件

success: function(data) {
    jQuery('#selectlist').html(data).find('select').chosen();
}
使用

尝试使用.find在html数据中查找元素,然后向其添加类


Hi Alex-这将样式应用于selectlist div,selectlist div是select的容器,而不是select本身。好的,因此select在ajax响应本身中,请参阅@Mohamed Yousef的答案,它应该可以正常工作,你只需在数据中找到select元素,addclassselect是否有你可以引用的id或类?这看起来很像,因为你想在这些元素上初始化choosen插件。添加所选的类选择不会起作用,请在新添加的元素上调用插件instead@A.Wolff因为像你这样的家伙,Stack Overflow应该给这个家伙买啤酒功能。因为你应该得到一杯啤酒。嗨,Mohamed Yousef,这确实增加了类,但样式仍然是默认的。@Jacques你问错问题了。。。初始化choosen插件而不是jQuery'selectlist'.htmldata.find'select'.Selected
success: function(data) {
    jQuery('#selectlist').html(data).addClass("form-control chosen-select");
}
jQuery('#selectlist').html(data).find('select').addClass('form-control chosen-select');