Last active
August 29, 2015 14:15
-
-
Save cuihaoleo/3291e94c62a8de5c362a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<select id="s1"> | |
<option value="CN">China</option> | |
<option value="JP">Japan</option> | |
</select> | |
<select id="s2"> | |
<option value="Beijing" data-country="CN">Beijing</option> | |
<option value="Shanghai" data-country="CN">Shanghai</option> | |
<option value="Tokyo" data-country="JP">Tokyo</option> | |
</select> | |
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script> | |
<script> | |
$("#s1").change(function () { | |
var country = $(this).val(); | |
$("#s2 option").hide(); | |
$("#s2 option[data-country=" + country + "]").show(); | |
$("#s2").val($("#s2 option[data-country=" + country + "]:first").val()); | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment