我想在使用javascript的下拉列表中有多個值,因此不需要在選擇標記的選項中寫入太多值,因此我使用下面的代碼來執行此操作,但它是當在Internet Explorer中打開時顯示不可見值意味着分配的空間是可見的但不是內容,在Chrome瀏覽器中它不顯示任何內容。在下拉列表中獲取不可見的值
<script>
function Time(){
selectHr();
selectMin();
selectSec();
}
function selectHr()
{
for(var x=1;x<=24;x++)
{
var option = document.createElement("option");
option.text = x;
option.value=x;
document.getElementById('dateTime_selHr').add(option);
}
}
function selectMin()
{
for(var x=1;x<=60;x++)
{
var option = document.createElement("option");
option.text = x;
option.value=x;
document.getElementById('dateTime_selMin').add(option);
}
}
function selectSec()
{
for(var x=1;x<=60;x++)
{
var option = document.createElement("option");
option.text = x;
option.value=x;
document.getElementById('dateTime_selSec').add(option);
}
}
</script>
</head>
<body onload="Time()">
<table class="table" id="dateTime_tbl">
<tr>
<td>
Camera
</td>
<td colspan="2">
<input type="text" name="camera" />
</td>
</tr>
<tr>
<td>
Time In Camera Date
</td>
<td>
Date <input type="text" name="date"/>
Time <input type="text" name="time" />
</td>
</tr>
<tr>
<td> Set Time</td>
<td>
<input type="radio" /> Set manually
</td>
</tr>
<tr>
<td></td>
<td>Date <input type="text" name="txtdate" />
Time
hr : <span> <select name="hr" id="dateTime_selHr"> </select> </span>
min : <span> <select name="min" id="dateTime_selMin" > </select> </span>
sec : <span> <select name="sec" id="dateTime_selSec" > </select> </span>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="radio" name="syncTime" />Synchronize with computer time
</td>
</tr>
<tr>
<td></td>
<td>
Date <input type="text" />
Time <input type="text" />
</td>
</tr>
<tr>
<td></td>
<td>
<input type="radio" /> Synchronize with SNTP server
</td>
</tr>
<tr>
<td></td>
<td>
SNTP Server <input type="text" style="width:200px"/>
</td>
</tr>
<tr>
<td></td>
<td>
Time Zone <span> <select name="timeZone">
<option></option>
</select></span>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="checkbox" /> Automatically adjust for daylight saving time changes
</td>
</tr>
<tr>
<td>
Date Format <span><select>
<option>-select-</option>
<option>YYYY/MM/DD</option>
<option>MM/DD/YYYY</option>
<option>DD/MM/YYYY</option>
</select></span>
</td>
<td>
Time Format <span> <select>
<option>-select-</option>
<option>12 hour format</option>
<option>24 hour format</option>
<option>DD/MM/YYYY</option>
</select></span>
</td>
</tr>
<tr>
<td>
Date Position <span><select>
<option>-select-</option>
<option>Bottom Left</option>
<option>Bottom Right</option>
</select></span>
</td>
<td>
Time Position <span> <select>
<option>-select-</option>
<option>Bottom Left</option>
<option>Bottom Right</option>
</select></span>
</td>
</tr>
</table>
<center>
<div id="dateTime_actionBtnsDiv">
<button type="button" name="ok" style="width:80px" id="dtTime_btns">OK</button>
<button type="button" name="cancel" style="width:80px" id="dtTime_btns">CANCEL</button>
</div>
</center>
</body>
有人可以幫我解決這個問題嗎?
可以讓我們知道什麼叫'隱形values'是什麼意思? –
我測試了你的代碼。它似乎工作正常。你遇到了什麼錯誤 ? – SpiderCode
@SpiderCode在IE 9對我來說,它顯示錯誤OP狀態:http://fiddle.jshell.net/tR2GC/show/ – Ming