回覆列表
  • 1 # 此去漸佳境

    JS 控制select選中項,程式碼如下:<html> <script type="text/javascript"> var selectedValue = "<%= request.getAttribute("line")%>"; function changeSelected(){ jsSelectItemByValue(document.getElementById("mySelect"),selectedValue); } function jsSelectItemByValue(objSelect,objItemText) { for(var i=0;i<objSelect.options.length;i++) { if(objSelect.options[i].value == objItemText) { objSelect.options[i].selected = true; break; } } } </script> <body onload="changeSelected()"> <select name="mySelect"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> </body> </html>

  • 2 # 此去漸佳境

    JS 控制select選中項,程式碼如下:<html> <script type="text/javascript"> var selectedValue = "<%= request.getAttribute("line")%>"; function changeSelected(){ jsSelectItemByValue(document.getElementById("mySelect"),selectedValue); } function jsSelectItemByValue(objSelect,objItemText) { for(var i=0;i<objSelect.options.length;i++) { if(objSelect.options[i].value == objItemText) { objSelect.options[i].selected = true; break; } } } </script> <body onload="changeSelected()"> <select name="mySelect"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> </body> </html>

  • 中秋節和大豐收的關聯?
  • 如何評價盧本偉復出造勢的聲音突然變小了?