2011-01-11 64 views
1

我需要禁用jsp頁面上的下拉菜單,但是如果html元素被禁用,它將不會被髮布。我嘗試使用與html元素具有相同標識的隱藏元素,但它仍未張貼元素。我使用struts.Any建議將不勝感激。Struts禁用字段

感謝 阿米努

回答

1

你的做法是好的,但你沒有使用正確的屬性。 name是根據請求發送的,而不是id屬性。

這裏是如何做到這一點(把它保存在一個名爲t.html文件)一個簡單的例子:

<script type="text/javascript"> 
    function disableCombo() { 
     var combo = document.getElementById("comboId"); 
     var txt = document.getElementById("txtId"); 
     combo.disabled = true; 
     txt.value = combo.value; 
    } 
</script> 

然後......

<body onload="javascript:disableCombo();"> 
    <form method="get" action="t.html"> 
     <select name="comboName" id="comboId"> 
      <option value="v1">Value 1</option> 
      <option value="v2" selected="selected">Value 2</option> 
      <option value="v3">Value 3</option> 
     </select> 
     <input type="hidden" name="comboName" id="txtId" value="waiting to see what happens" /> 
     <input type="submit" value="watch the address bar" /> 
    </form> 
</body> 

當您按下提交,值的組合(當您禁用加載組合時,已經複製到隱藏字段中)在請求上發送。

+0

我試過這樣做,仍然沒有發佈價值。 下面是我的代碼:

的Onload IM呼叫: \t功能disableDropDown() \t \t { \t \t變種狀態=文檔.getElementById( '國家'); \t \t var state1 = document.getElementById('State1'); \t state1.value = state.value; \t \t state.disabled = true; \t \t} – user573010 2011-01-12 16:13:39