编辑的时候选择一个很多选择的东西,所以把文章按照等级来进行选择

action代码:

$category=new Model('Category');
        $article=new Model('Article');
        $yila=$category->query("select * from zs_category where pid  in (select id from zs_category where pid=0)");
        $erla=$category->query("select * from zs_category where pid in  (select id from zs_category where pid in (select id from zs_category where pid=0))");
        $sanla=$article->select();
        $count=count($yila);
        $count1=count($erla);
        $this->assign("count",$count);
        $this->assign("count1",$count1);
        $this->assign("yila",$yila);
        $this->assign("erla",$erla);
        $this->assign("sanla",$sanla);

模版代码:


<label>所属文章:</label>     
            <SELECT ID="s1">
             <OPTION selected></OPTION>
            </SELECT>
            <SELECT ID="s2">
            <OPTION></OPTION>
            </SELECT>
            <select id="s3"  name="aid">
            <option></option>
            </select>
                                                                                                                                
            <input type="submit" value="编辑"/>



模版中的js代码:

<script language="javascript" > 
  function CLASS_LIANDONG_YAO(array)
  {
   //数组,联动的数据源
    this.array=array;
    this.indexName='';
    this.obj='';
    //设置子SELECT
    // 参数:当前onchange的SELECT ID,要设置的SELECT ID
      this.subSelectChange=function(selectName1,selectName2)
    {
                                                                             
    var obj1=document.all[selectName1];
    var obj2=document.all[selectName2];
    var objName=this.toString();
    var me=this;
    obj1.onchange=function()
    {
        me.optionChange(this.options[this.selectedIndex].value,obj2.id)
    }
    }
    //设置第一个SELECT
    // 参数:indexName指选中项,selectName指select的ID
    this.firstSelectChange=function(indexName,selectName)
    {
    this.obj=document.all[selectName];
    this.indexName=indexName;
    this.optionChange(this.indexName,this.obj.id)
    }
  // indexName指选中项,selectName指select的ID
    this.optionChange=function (indexName,selectName)
    {
    var obj1=document.all[selectName];
    var me=this;
    obj1.length=0;
    obj1.options[0]=new Option("请选择",'');
    for(var i=1;i<this.array.length;i++)
    { 
        if(this.array[i][1]==indexName)
        {
        //alert(this.array[i][1]+" "+indexName);
      obj1.options[obj1.length]=new Option(this.array[i][2],this.array[i][0]);
        }
    }
    } 
  }
  </script>
                                                                           
  <script language="javascript">
//例子1-------------------------------------------------------------
//数据源
var array=new Array();
  <volist name="yila" id="yila">
        array[{$i}]=new Array("{$yila['name']}","根目录","{$yila['name']}");
  </volist>
  <volist name="erla" id="erla">
        array[{$i}+{$count}]=new Array("{$erla['name']}","{$erla['pid']|getCategoryName}","{$erla['name']}");
  </volist>
  <volist name="sanla" id="sanla">
        array[{$i}+{$count}+{$count1}]=new Array("{$sanla['id']}","{$sanla['tid']|getCategoryName}","{$sanla['title']}");
  </volist>
                                                                           
                                                                            
  //--------------------------------------------
  //这是调用代码
  var liandong=new CLASS_LIANDONG_YAO(array) //设置数据源
  liandong.firstSelectChange("根目录","s1"); //设置第一个选择框
  liandong.subSelectChange("s1","s2"); //设置子级选择框
  liandong.subSelectChange("s2","s3");
                                                                           
                                                                           
                                                                             
</script>

然后把模版提交上来的数据添加到数据可就可以了。

问题:option中没有value怎样提交数据到服务器?

array[{$i}]=newArray("{$yila['name']}","根目录","{$yila['name']}");

这句里面,第二个参数是父级的名字,第三个参数是显示的名字

第一个参数就是value,同时它也是别人的父级名字


--------------------------------------------

开发过程中遇到一个问题,就是js显示不出来错误,但是之前是可以的,对比一看,是增加某一个功能之后添加了相同名字的js动作,导致js显示错误,所以一定要注意js的名字不能一样