2009-08-21 53 views
0
 <div class="yui-gd"> 
      <div class="yui-u first"><label for="${args.htmlid}-addContent">${msg("label.HowToAddContent")}:</label></div> 
      <div class="yui-u"> 
       <select id="addContent" name="addContent" onchange="dropdown(this)"> 
        <option value="1" selected="selected">${msg("label.generateFromDescription")}</option> 
        <option value="2">${msg("label.uploadFile")}</option> 
       </select> 
       </div> 

     </div> 
<script type="text/javascript">//<![CDATA[ 
     function dropdown(sel){ 
       //if(document.getElementById("addContent").value == "1") 
      if(sel.value == "0"){ 
       document.getElementById('desc').style.display = 'block' 
     } 
      else { 
      document.getElementById('desc').style.display = 'none' 
     } 
     }  
//]]></script> 

我写它是因为我想添加事件处理程序到选择框中,它在Firefox中运行良好,但在IE中它总是抛出空异常。 即使通过我使用attachEvent,它仍然无法在IE中工作。 如果我在上面使用document.getElementById(“addContent”),它总是会抛出空异常!但是,所有这些东西在Firefox中运行良好!alfresco ----如何将事件处理程序添加到冲浪模板中?

有人能告诉我为什么吗? 在此先感谢!

回答

0

您使用哪个IE版本? 如果它是旧版本,请尝试通过以下选项获取选定值:

var selectedValue = sel.options[sel.selectedIndex].value;