這是一個開關。我曾經有過顯示問題:無法在Firefox中使用。現在是IE6讓我瘋狂。control.style.display ='none';在IE6中只有
我正在修改一個朋友的公司的網站,他不幸仍在IE6上運行大部分機器。我有一個網頁表單(ASP生成,但這不是我的問題所在)存儲聯繫信息,如他們的地址。
因爲他們與國際客戶打交道,他們需要地址系統儘可能容易使用。所以對於「國家」,我創建了一個與世界上235個國家的下拉菜單。然後,我創建了一個與美國50個州的下拉菜單和一個用於輸入其他國家的省/城鎮/等的文本框。
我必須很聰明,所以我做了所有這些動態:選擇美國和省文字消失,國家下拉菜單出現。選擇任何其他國家,他們逆轉。它在Firefox,Safari,Opera,IE7,IE8和我自己的腦海中運行得非常漂亮。 IE6扼殺它。當然。因爲這是我需要的瀏覽器。
無法獲取顯示屬性。無效參數
這裏是我的腳本標頭,它的污垢簡單:
function ToggleState(changeto)
{
//Get the controls
var stateTitle = document.getElementById('statelabel');
var stateCombo = document.getElementById('state');
var provTitle = document.getElementById('provlabel');
var provText = document.getElementById('province');
var countryCombo = document.getElementById('country');
//We're hiding the state dropdown and showing the province box
if(changeto == "Province"){
//Update the Province Link so it's not active anymore
provTitle.href = "javascript:function(){return;}";
provTitle.style.color="#000";
//Show the Province box and make it take up space
provText.style.visibility = 'visible';
provText.style.display = 'inherit';
//Make the State Link active
stateTitle.href = "javascript:ToggleState('State');";
stateTitle.style.color="#00A";
//Hide the State dropdown and keep it from eating up GUI room
stateCombo.style.display = "none";
stateCombo.style.visibility = "hidden";
stateCombo.value = "";
//Shift the country off of US because we're not in Kansas anymore
if(countryCombo.value == "US") countryCombo.value = "";
//We're hiding the province box and showing the State dropdown
}else if(changeto == "State"){
//Kill the link, make the box show up
stateTitle.href = "javascript:function(){return;}";
stateTitle.style.color="#000";
stateCombo.style.visibility = "visible";
stateCombo.style.display = "inherit";
//Activate the link and kill the Province box
provTitle.href = "javascript:ToggleState('Province');";
provTitle.style.color="#00A";
provText.style.display = "none";
provText.style.visibility = "hidden";
provText.value = "";
//Make sure we're on the US...
if(countryCombo.value != "US") countryCombo.value = "US";
}else return;
}
//Fairly self-evident. If you change the country from US it trips the hide State
// If you change TO US trip the hide Province
function UpdateState(obj){
if (obj.value == "US" &&
document.getElementById('state').style.visibility == "hidden")
ToggleState('State');
else if (obj.value != "US" &&
document.getElementById('state').style.visibility == "visible")
ToggleState('Province');
}
和身體(下拉菜單上剪下來的簡潔)...
<div class="ctrlHolder">
<label for="state">
<a id="statelabel" href="javascript:function(){return;}" style="text-decoration:none;color:#000">State</a>
/<a id="provlabel" href="javascript:ToggleState('Province');" style="text-decoration:none;color:#00A">Province</a>
</label>
<input type="text" id="province" class="textInput" style="display:none;visibility:hidden;" />
<select id="state" style="display:inherit;visibility:visible;">
<option selected="selected" value="">-Not Known-</option>
<option value="TX">Texas</option>
<option value="WY">Wyoming</option>
</select>
</div>
<div class="ctrlHolder">
<label for="country">Country</label>
<select id="country" onchange="UpdateState(this);">
<option value="">-Not Known-</option>
<option value="GB">United Kingdom</option>
<option selected="selected" value="US">United States</option>
</select>
</div>
我在一個爲什麼IE6不會接受它的損失。這裏有一些我已經忘記/阻止了我的想法。有任何想法嗎??
好的。如果我移動它來阻止它將使我的格式變得醜陋,除非我手動定位。我會使用內聯,但不ie6也有內聯的問題呢? – Shawn 2010-02-10 22:14:58
我不這麼認爲,'inline'應該是o.k. (畢竟,它是所有內聯元素(如a,span ...)的默認'display') – 2010-02-10 22:25:14
可能發誓IE6有一個內聯錯誤,但後來我睡了。將我的所有繼承改爲內聯,現在似乎正在全面開展工作。謝謝,Pekka! – Shawn 2010-02-10 22:27:24