我是这里的 jQuery 菜鸟,我想弄清楚如何将此脚本移动到外部 .js 文件。我已经尝试复制它并在页面上引用,但它似乎不起作用。
我在这里想念什么?
<script type="text/javascript">
$(document).ready(function () {
$('#YearD').change(function () {
var selectedYear = $(this).val();
if (selectedYear != null && selectedYear != '') {
$.getJSON('@Url.Action("Months")', { year: selectedYear }, function (months) {
var monthsSelect = $('#Month');
monthsSelect.empty();
$.each(months, function (index, month) {
monthsSelect.append($('<option/>', {
value: month.value,
text: month.text
}));
});
});
}
});
});
</script>
<script type="text/javascript">
$('#Month').change(function () {
var selectedMonth = $(this).val();
if (selectedMonth != null && selectedMonth != '') {
$.getJSON('@Url.Action("Days")', { month: selectedMonth }, function (days) {
var daysSelect = $('#Day');
daysSelect.empty();
if (days == 0) {
daysSelect.css("visibility", "hidden");
}
else {
daysSelect.css("visibility", "visible");
}
$.each(days, function (index, day) {
daysSelect.append($('<option/>', {
value: day.value,
text: day.text
}));
});
});
}
});
</script>