生成选择清单项目问题 [英] Generate Select List Item Issue

查看:82
本文介绍了生成选择清单项目问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JQuery生成动态选择列表项菜单

Generate Dynamic Select List Item Menu using JQuery

这是Div:

<select name="CountryID" id="CountryID">
<option value="" id="">Select the Country</option>
......
</option>
</select>
<div id='result' name="result">
<select  id="name">
<option value="" disabled>Please select above</option>
</select>
</div>
<div id='resulta' name="resulta">
<select  id="name">
<option value="" disabled>Please select above</option>
</select>
</div>

这是我的脚本:

<script>
var ab=$.noConflict();
ab(document).ready(function(){
ab("#CountryID").change(function(){
    var CountryID=ab("#CountryID").val();
    ab.post("globalregiongenerator",
    {
      CountryID:CountryID
    },
    function(data,status){
       ab( "#result" ).html( data );
    });
  });
});
</script>


<script>
var ac=$.noConflict();
ac(document).ready(function(){
  ac("#RegionName").change(function(){
  //alert('action triggered');
    var RegionName=ab("#RegionName").val();
    ac.post("globalcitygenerator",
    {
      RegionName:RegionName
    },
    function(data,status){
       ac( "#resulta" ).html( data );
    });
  });
});
</script>

在这里,我生成我的选择菜单列表

Here i generate my Select Menu List

public function globalregiongenerator()
    {
    $CountryID = Input::get('CountryID');
    $roles = DB::table('region')->where('CountryID', $CountryID)->lists('regionname','regionid');   
    echo "<select  id='RegionName' name='RegionName'>"; 
    foreach ($roles as $value) 
    {
    echo "<option value=".$value.">".$value."</option>";
    }
    }

public function globalcitygenerator()
    {
    $RegionName = Input::get('RegionName');
    $roles = DB::table('city')->where('RegionName', $RegionName)->lists('regionname','regionid');   
    echo "<select  id='CityName' name='CityName'>"; 
    foreach ($roles as $value) 
    {
    echo "<option value=".$value.">".$value."</option>";
    }
    }

我能够生成首选菜单列表"项,但是即使我尝试在其中添加警报,动作ac("#RegionName").change(function(){也不会触发.

I can able to generate the First Select Menu List Item, But the action ac("#RegionName").change(function(){ is not triggering, even i tried putting alert inside it.

第二个列表菜单项<select id='RegionName' name='RegionName'>是不是在页面中创建的还是其他内容.

Is the Second List Menu Item <select id='RegionName' name='RegionName'> not creating in the page or what.

我该怎么做?

注意:

我什至在ab( "#result" ).html(data); 的此答案下尝试了ab('#RegionName').selectmenu('refresh', true); ,但没有成功

I even tried ab('#RegionName').selectmenu('refresh', true); under the ab( "#result" ).html(data); from this answer but it didn't worked

如果我们追加$( "#result" ).append ( data );,将出现另一个菜单,那不是我所需要的. 我需要已经存在的前三个菜单.

If we append $( "#result" ).append ( data ); another menu will appear, that isn't i need. I need to the first three menu already there.

推荐答案

好像您没有关闭<select,我想您也需要echo </select>.对于处理程序,请尝试

Looks like you're not closing <select, I think you need echo </select> as well. For the handler try

ac(document).on("click", "#RegionName"

您还有一个var RegionName=ab("#RegionName").val();应该是var RegionName=ac("#RegionName").val();

更新:

行应该是

RegionName=ac(this).val();

Update2

更改

echo "<option value=".$value.">".$value."</option>";

echo "<option value='".$value."'>".$value."</option>";

这篇关于生成选择清单项目问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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