2012-03-06 146 views
1

我有以下代碼:如何刪除選擇字段中的列表選項項?

function removeUsers() 
     { 

      var removedUsers = document.getElementById('<%=removedUsers.ClientID%>'); 
      var lbCurrent = document.getElementById('<%=lbCurrent.ClientID%>'); 

      if (lbCurrent && lbCurrent.selectedIndex != -1) 
      { 
       for(i=lbCurrent.length-1; i>=0; i--) 
       { 
        if(lbCurrent.options[i].selected) 
        { 
         //add the removed user to the removedUsers var 
         removedUsers.value += lbCurrent.options(i).value + ";"; 
         lbCurrent.options[i] = null; 
        } 
       } 
      } 
      selectAllItems();  
     } 

這造成我的問題在Firefox:

removedUsers.value += lbCurrent.options(i).value + ";"; 

別人的幫助?

由於

+1

沒有相應的HTML這是沒有意義的。 – 2012-03-06 15:49:17

+0

另外,你可以發表渲染的腳本?由於'<%= removedUsers.ClientID%'在服務器端看起來很可疑。 JavaScript適用於客戶端,因此我們需要查看呈現的HTML/JavaScript,如'view source'所示。 – 2012-03-06 15:51:40

回答

1
removedUsers.value += lbCurrent.options(i).value + ";"; 

應該是

removedUsers.value += lbCurrent.options[i].value + ";"; 

假設lbCurrent.optionsArray

+0

偉大的工作 - 感謝您的幫助:) – user1177860 2012-03-06 16:04:10

1

嘗試將其更改爲此?

removedUsers.value += lbCurrent.options[i].value + ";"; 
0

你是mac用戶嗎?通常情況下,Firefox會遭受JavaScript掛斷,而其他瀏覽器對處理擴展的方式不做處理。 Firefox經常建議以安全模式啓動(暫時禁用所有插件)。可能與您正在運行的功能以及您的Firefox插件之一有衝突。在mac上以安全模式運行Firefox - 按住選項打開瀏覽器 - 更多信息請點擊:http://kb.mozillazine.org/Safe_Mode#Starting_Safe_Mode

我在自己的編碼中遇到了一些JavaScript衝突。

如果這樣不能解決問題,可以提供一些關於究竟是/不工作的更多細節?此外,螢火蟲報告任何JavaScript錯誤?

謝謝,