Skip to content

Instantly share code, notes, and snippets.

@cuihaoleo
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuihaoleo/3291e94c62a8de5c362a to your computer and use it in GitHub Desktop.
Save cuihaoleo/3291e94c62a8de5c362a to your computer and use it in GitHub Desktop.
<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