在我的 _Layout.cshtml 中,我有以下内容:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Intranet Ads</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<script type="text/javascript">
function search() {
var searchVal = $('#txtSearchString').val();
$('#adResults #summary').each(function () {
if (searchVal == '') {
$(this).parent().show();
} else {
$(this).not(':contains(' + searchVal + ')').parent().hide();
}
});
}
function openEditAd(val) {
if (val != 'admin') {
$("#edit-content,#edit-background").toggleClass("active");
$("#txtConfirmationEdit").text = "";
} else {
$("#edit-content-admin,#edit-background-admin").toggleClass("active");
$("#txtConfirmationEdit").text = "";
}
}
function closeEditAd(permission) {
if (permission != 'admin') {
if ($("#txtConfirmationEdit").val().trim() != "") {
var url = '@Url.Action("Edit", new { id = "__id__" })';
window.location.href = url.replace('__id__', $("#txtConfirmationEdit").val());
}
$("#edit-content,#edit-background").toggleClass("active");
} else {
if ($("#txtConfirmationAdmin").val().trim() != "") {
var url = '@Url.Action("Edit", new { id = "__id__" })';
window.location.href = url.replace('__id__', $("#txtConfirmationAdmin").val());
}
$("#edit-content-admin,#edit-background-admin").toggleClass("active");
}
}
$(document).ready(function () {
// Handler for .ready() called.
console.log("hi");
});
</script>
</head>
<body>
...
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
我刚刚添加了:
$(document).ready(function () {
// Handler for .ready() called.
console.log("hi");
});
最后,我正在尝试实现一个日期选择器,但我得到了
JavaScript 运行时错误:“$”未定义
正如您在我的其他函数中看到的那样,我正在使用 jQuery 命令……这是什么原因?
当我也有这个时,我得到了完全相同的错误:
$(document).ready(
function () {
$('.datepicker').datepicker({
changeMonth: true,
changeYear: true,
minDate: "-99Y",
dateFormat: "dd/mm/yyyy"
});
});