gpt4 book ai didi

javascript - 表单验证不是一个函数 - Bootstrap datepicker

转载 作者:行者123 更新时间:2023-12-02 15:22:03 25 4
gpt4 key购买 nike

我想使用基于此示例的 Bootstrap 日期选择器:

http://formvalidation.io/examples/bootstrap-datepicker/

这是我的 .html 代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<!-- ################ -->
<!-- ####Bootstrap### -->
<script src="bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="bootstrap-3.3.6-dist/css/bootstrap.min.css" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker.min.css" />
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker3.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.4.5/js/bootstrapValidator.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.4.5/css/bootstrapValidator.min.css" rel="stylesheet"/>
<!-- ################ -->
<!-- #####Custom##### -->
<script src="Scripts/datepicker.js"></script>
<link rel="stylesheet" href="CSS/dashboard.css" />
<!-- ################ -->
</head>
<body>
<!-- Top bar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">NY Noise Map</a>
</div>
</div>
</nav>

<!-- Content -->
<div class="container-fluid">
<!-- Right Panel -->
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<!-- Start Date -->
<form id="startDate" method="post" class="dateRangeForm form-vertical">
<div class="form-group">
<label class="control-label">Start Date:</label>
<br></br>
<div class="date">
<div class="input-group input-append date dateRangePicker">
<input type="text" class="form-control" name="date" />
<span class="input-group-addon add-on">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</form>
<!-- End Date -->
<form id="endDate" method="post" class="dateRangeForm form-vertical">
<div class="form-group">
<label class="control-label">End Date:</label>
<br></br>
<div class="date">
<div class="input-group input-append date dateRangePicker">
<input type="text" class="form-control" name="date" />
<span class="input-group-addon add-on">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</form>
</div>
</div>
</body>

这是datepicker.js文件:

$(document).ready(function() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if (dd < 10)
dd='0'+dd

if (mm < 10)
mm='0'+mm

today = mm+'/'+dd+'/'+yyyy;

$('.dateRangePicker')
.datepicker({
format: 'mm/dd/yyyy',
startDate: '01/01/2010',
endDate: today
})
.on('changeDate', function(e) {
// Revalidate the date field
$('.dateRangeForm').formValidation('revalidateField', 'date');
});

$('.dateRangeForm').formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
date: {
validators: {
notEmpty: {
message: 'The date is required'
},
date: {
format: 'MM/DD/YYYY',
min: '01/01/2010',
max: today,
message: 'The date is not a valid'
}
}
}
}
});
});

我目前收到此错误:

TypeError: $('.dateRangeForm').formValidation is not a function. (In '$('.dateRangeForm').formValidation', '$('.dateRangeForm').formValidation' is undefined)
(anonymous function)datepicker.js:25
jjquery-2.1.0.min.js:1:26681
fireWithjquery-2.1.0.min.js:1:27490
readyjquery-2.1.0.min.js:1:29294
Ijquery-2.1.0.min.js:1:29458

我也不知道为什么。任何帮助将不胜感激。

最佳答案

尝试使用 $(document).load(function() { 而不是 $(document).ready(function() {

如果上述方法不起作用,还可以将 $ 传递给 $(document).ready(function($) { 就绪函数。

关于javascript - 表单验证不是一个函数 - Bootstrap datepicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33963782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com