【问题标题】:is there any way to add optgroup label to dependent dropdownlist with javascript有没有办法用javascript将optgroup标签添加到依赖下拉列表中
【发布时间】:2015-04-07 16:59:50
【问题描述】:

我确实需要一些关于我的依赖下拉列表的帮助。

我找到了此代码,但我想在子类别中添加 optgroup 标签,尝试了任何方法但找不到答案。

谢谢,

    case "Home Ware" :
    <optgroup label="Fruits">;
document.formname.subcategory.optgroup      
 document.formname.subcategory.options[0]=new Option("Select Sub-Category","");
 document.formname.subcategory.options[1]=new Option("Air-Conditioners/Coolers","Air-Conditioners/Coolers");
 document.formname.subcategory.options[2]=new Option("Audio/Video","Audio/Video");
 document.formname.subcategory.options[3]=new Option("Beddings","Beddings");
 document.formname.subcategory.options[4]=new Option("Camera","Camera");
 document.formname.subcategory.options[5]=new Option("Cell Phones","Cell Phones");

【问题讨论】:

    标签: javascript html joomla combobox dependencies


    【解决方案1】:
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <script language="javascript" type="text/javascript">
     function dropdownlist(listindex)
     {
    
    document.formname.subcategory.options.length = 0;
     switch (listindex)
     {
    
     case "Home Ware" :
        <optgroup label="Fruits">;
    document.formname.subcategory.optgroup      
     document.formname.subcategory.options[0]=new Option("Select Sub-Category","");
     document.formname.subcategory.options[1]=new Option("Air-Conditioners/Coolers","Air-Conditioners/Coolers");
     document.formname.subcategory.options[2]=new Option("Audio/Video","Audio/Video");
     document.formname.subcategory.options[3]=new Option("Beddings","Beddings");
     document.formname.subcategory.options[4]=new Option("Camera","Camera");
     document.formname.subcategory.options[5]=new Option("Cell Phones","Cell Phones");
    
    
     break;
    
     case "Education" :
     document.formname.subcategory.options[0]=new Option("Select Sub-Category","");
     document.formname.subcategory.options[1]=new Option("Colleges","Colleges");
     document.formname.subcategory.options[2]=new Option("Institutes","Institutes");
     document.formname.subcategory.options[3]=new Option("Schools","Schools");
     document.formname.subcategory.options[4]=new Option("Tuitions","Tuitions");
     document.formname.subcategory.options[5]=new Option("Universities","Universities");
    
     break;
    
     case "Books" :
     document.formname.subcategory.options[0]=new Option("Select Sub-Category","");
     document.formname.subcategory.options[1]=new Option("College Books","College Books");
     document.formname.subcategory.options[2]=new Option("Engineering","Engineering");
     document.formname.subcategory.options[3]=new Option("Magazines","Magazines");
     document.formname.subcategory.options[4]=new Option("Medicine","Medicine");
     document.formname.subcategory.options[5]=new Option("References","References");
      document.getElementById("optg1").label = "first group";
     break;
    
     }
     return true;
     }
    
     </script>
    
    
    <form id="formname" name="formname" method="post" action="submitform.asp" >
     <table width="50%" border="0" cellspacing="0" cellpadding="5">
     <tr>
     <td width="41%" align="right" valign="middle">Category :</td>
     <td width="59%" align="left" valign="middle"><select name="category" id="category" onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);">
    
     <option value="">« Select Services »</option>
     <option value="Home Ware">Personalized Facilitation Services</option>
     <option value="Education">Medical Second Opinion Services</option>
    
     </select></td>
     </tr>
     <tr>
     <td align="right" valign="middle">Sub Category :
     </td>
     <td align="left" valign="middle"><script type="text/javascript" language="JavaScript">
     document.write('<select name="subcategory"><option value="">Select Sub-Category</option></select>')
     </script>
     <noscript><select name="subcategory" id="subcategory" >
     <option value="">« Select Expertise »</option>
     </select>
     </noscript></td>
     </tr>
     </table>
    
    </form>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-15
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 2021-08-05
      • 1970-01-01
      相关资源
      最近更新 更多