我一直在尝试更好地掌握 jQuery,并且一直在想出一些随机页面来测试其中的一些。我制作了一个小型的模拟旅行社页面,其中包含一个带有出发地和目的地国家选项的表格。默认出发地/目的地是美国,美国的第二个选项出现在其下方。当用户选择美国以外的其他内容时,states 选项会消失,Chrome 除外。
网站: http: //www.stephenweigel.com/portfolio/somewheresomehow
脚本:(确实有 $(document).ready(function() ,不认为我需要发布整个 JS 文件)
$('#destination').click(function(){
// Show US States if Destination is US
var destination = $('#destination').val();
var domestic = 'USA';
if (destination == domestic) {
$('#usDest').css("display","inline");
} else {
$('#usDest').css("display","none");
}
html:
<div>
<select name="destination" id="destination">
<option value="USA" selected="selected">USA</option>
<option value="Canada">Canada</option>
<option value="Mexico">Mexico</option>
<option value="Italy">Italy</option>
<option value="France"> France </option>
<option value="Spain"> Spain </option>
</select> <!--end destination-->
</div>
<div>
<select name="usDest" id="usDest">
<option value="Alabama" selected="selected">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
<option value="Arkansas">Arkansas</option>
<option value="California">California</option>
<option value="Colorado">Colorado</option>
<option value="Connecticut">Connecticut</option>
<option value="Delaware">Delaware</option>
<option value="District of Columbia">District of Columbia</option>
<option value="Florida">Florida</option>
<option value="Georgia">Georgia</option>
<option value="Hawaii">Hawaii</option>
<option value="Idaho">Idaho</option>
<option value="Illinois">Illinois</option>
<option value="Indiana">Indiana</option>
<option value="Iowa">Iowa</option>
<option value="Kansas">Kansas</option>
<option value="Kentucky">Kentucky</option>
<option value="Louisiana">Louisiana</option>
<option value="Maine">Maine</option>
<option value="Maryland">Maryland</option>
<option value="Massachusetts">Massachusetts</option>
<option value="Michigan">Michigan</option>
<option value="Minnesota">Minnesota</option>
<option value="Missouri">Missouri</option>
<option value="Montana">Montana</option>
<option value="Nebraska">Nebraska</option>
<option value="Nevada">Nevada</option>
<option value="New Hampshire">New Hampshire</option>
<option value="New Jersey">New Jersey</option>
<option value="New Mexico">New Mexico</option>
<option value="New York">New York</option>
<option value="North Carolina">North Carolina</option>
<option value="North Dakota">North Dakota</option>
<option value="Ohio">Ohio</option>
<option value="Oklahoma">Oklahoma</option>
<option value="Oregon">Oregon</option>
<option value="Pennsylvania">Pennsylvania</option>
<option value="Rhode Island">Rhode Island</option>
<option value="South Carolina">South Carolina</option>
<option value="South Dakota">South Dakota</option>
<option value="Tennessee">Tennessee</option>
<option value="Texas">Texas</option>
<option value="Utah">Utah</option>
<option value="Vermont">Vermont</option>
<option value="Virginia">Virginia</option>
<option value="Washington">Washington</option>
<option value="West Virginia">West Virginia</option>
<option value="Wisconsin">Wisconsin</option>
<option value="Wyoming">Wyoming</option>
</select> <!-- end usDest-->
</div>
也许我遗漏了一些东西,但它适用于 Firefox、Safari 和 Internet Explorer 9 但不适用于 chrome 似乎很奇怪。
我也尝试过使用:
$('#origin').click(function(){
var origin = $('#origin').val();
var domestic = 'USA';
if (origin == domestic) {
$('#usOrigin').removeClass("invisible");
$('#usOrigin').addClass("visible");
} else {
$('#usOrigin').removeClass("visible");
$('#usOrigin').addClass("invisible");
}
与CSS:
.visible {
display: inline;
}
.invisible {
display: none;
}
但这在 chrome 中也不起作用。(适用于其他浏览器)
任何建议,将不胜感激。