我想以动态方式使用多个select2 onchange函数 [英] i want to use multiple select2 onchange function in a dynamic way

查看:79
本文介绍了我想以动态方式使用多个select2 onchange函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的代码中放入select2函数,但不知道放在哪里 .select2() function

i有这个 .append($(<?php echo json_encode($ property_address1);?>))
my model`

I want to put select2 function in my code but don't know where to put that .select2() function
i have this .append($(<?php echo json_encode($property_address1); ?>)) my model `

   function property_address1()
   {
     $query = $this->db->query('SELECT host,price,city,property_thumbnail, apartments_type, contactnumber, contactperson,photographlinks,emailid, propertyaddress FROM tbl_contacts')->result();
     $output = '<select id="neww" class="property_add_ form-control">';


    foreach ($query as $row) 
    {
        //echo $row->location;
        $output .= "<option value='". $row->propertyaddress ."'";
        $output .= " data-propertyaddress='" . $row->propertyaddress ."'" ;
        $output .= " data-host_name='" . $row->host ."'" ;

        $output .= " data-apartments_type ='" . $row->apartments_type."'" ;

        $output .= " data-city ='" . $row->city."'" ;

        $output .= " data-property_thumbnail='" . $row->property_thumbnail."'" ;

        $output .= " data-price='" . $row->price."'" ;

        $output .= " data-contactperson='" . $row->contactperson ."'" ;
        // $output. = $row->pincode.", ".$row->city.", ".$row->location;
        $output .= " data-photographlinks='" . $row->photographlinks ."'" ;
        $output .= " data-emailid='" . $row->emailid ."'" ;
        $output .= " data-contactnumber='". $row->contactnumber . "'>" ;
        $output .=   $row->host . ' , '.$row->propertyaddress . ' ,'.$row->price. ' ,'.$row->apartments_type. ' , '. $row->contactperson . ' , ' . $row->contactnumber. "</option>";
    }
    $output .= '</select>';
    //var_dump($output);
    return $output;

    }`

我的控制器

  public function test($id = null)
    {
        $this->layout->set(
                array(
                    'property_address1' => $this->mdl_quotes->property_address1()
                     )
                 );
        $this->load->model('mdl_quotes');
        $this->layout->buffer('content', 'quotes/test'); 
        $this->layout->render();
    }

Dhaval Panchal查看此更新的屏幕截图

这是更好理解的截图..请看看谢谢

推荐答案

插入CSS& JS文件在页面中插入此代码后,页面中的JS文件。

Insert CSS & JS file in your page then after JS file insert this code in your page.

<script type="text/javascript">
    $(document).ready(function() {
        $('#neww').select2();
    });
</script>

要更新选项,请参阅以下代码。

To update options, see below code.

var option = new Option("text", "id");
$("#neww").append(option);
$("#neww").trigger("change");

这篇关于我想以动态方式使用多个select2 onchange函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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