【问题标题】:Jquery Chosen Ajax call not rendering the optionsJquery Chosen Ajax 调用不呈现选项
【发布时间】:2015-03-22 18:03:44
【问题描述】:

我使用的是 Jquery 1.6.4 并选择了 1.4.1。我在从 AJAX 渲染选项时遇到问题。以下是我的代码。

<script type="text/javascript">
    jQuery(document).ready(function(){
		jQuery(".chzn").data("placeholder","Select Frameworks...").chosen();
		jQuery("#item").chosen().change(function(e, params){
			 values = jQuery("#item").chosen().val();
			 $('#item_selected').val(values);
		});
	});


$('#customer').click(function() {
  
  var url = "ajax_common.php?action=getItem&companyid=1";
  $.ajax({
    type: 'GET',
    url: url,
    dataType: 'html',
    success: function(data){
      $("#item option").remove();
      $("#item").append(data);
      $("#item").trigger("liszt:updated");
    }
  });
    </script>
    
<select class="chzn inpt-fld" multiple="true" name="item" id="item" style="width: 96%">
</select>

但该值未附加在多选下拉列表中?

【问题讨论】:

    标签: javascript jquery html ajax jquery-chosen


    【解决方案1】:

    问题似乎来自于您输出 ajax 响应的方式。您不能在选择标记中动态附加选项,因为它不属于当前选择。这意味着此选择无法检测到以前不存在的选项(作为硬代码)。

    您应该在 ajax_common.php 中同时包含 select 和 option,并在 div 中呈现为 innerHtml。

    // inside ajax_commond.php :
    <select class="chzn inpt-fld" multiple="true" name="item" style="width: 96%">
    <option> xxxx </option>
    </select>
    
    // render the ajax response in : 
    <div id="item"></div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多