当然,通过使用objects
,您可以快速轻松地完成此操作,例如:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title>Character Creation</title>
<meta charset="UTF-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(function(){
//Range
var slider = $("#slider"), val = slider.val(), output = $("#output");
output.html(val);
slider.on("change", function(){
output.html($(this).val());
});
//Change range values
var minMax = {
human: [10, 80],
faela: [10, 70],
domovoi: [12, 99],
arcon: [5, 80],
tsaaran: [20, 100]
};
$("#Race").on("change", function(){
var ages = minMax[$(this).val()];
if(ages) {
slider.attr({
min: ages[0],
max: ages[1]
});
output.html(slider.val());
}
});
});
</script>
</head>
<body>
<h1>Form</h1>
<form>
<fieldset>
<legend>Appearance</legend>
<p>
<label for="Race">Select Race:</label>
<select name="Race" id="Race">
<option value="human">Human</option>
<option value="faela">Faela</option>
<option value="domovoi">Domovoi</option>
<option value="arcon">Arcon</option>
<option value="tsaaran">Tsaaran</option>
</select>
</p>
<p>
<label for="Gender">Select Gender</label>
<select name="Gender" id="Gender">
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
</p>
<p>
<label for="slider">Select Age:</label> <input name="slider" type="range" min="14" max="60" id="slider" value="10" />
<span id="output"></span>
</p>
</fieldset>
</form>
</body>
</html>