私はここでは 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>