抱歉,我是Javascript的新手。我在Bootstrap Collapse上做了一些简单的验证。我正在使用此处给出的BS警报:
<div id ="alertMessage" class="alert alert-danger fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Info!</strong> This alert box could indicate a neutral informative change or action.
</div>
只需放在HTML页面上即可。但是,我希望它只触发 IF JS验证脚本失败。问题是,一旦我将它放入脚本,它就不再淡出。我认为Bootstrap文件中的JS不是以某种方式制定的。更可能的是,我认为我的脚本无法正常工作,因为其他面板也没有正确关闭。
$(document).ready(function () {
$("input.btn").mousedown(function () { // THIS IS THE SUBMIT BUTTON OMN THE FORM
var required = $("input.required").val(); // WE GRAB THE VALUES OF THE "REQUIRED FIELDS"
if (required == "") { // IF ANY OF THE REQUIRED FIELDS ARE EMPTY WE EXECUTE THE FOLLOWING:
$("#collapseOne").collapse('show'); // THIS ONE HAS ALL THE CUSTOMER DETAILS WHERE THE VALIDATION ERROR IS
$("#collapseTwo").collapse('hide');
$("#collapseThree").collapse('hide');
$("#alertMessage").append("<p class='alert alert-danger' >You have Missed Off One or More Required Fields !</p>");
}
});
});
当我想要它时会发生什么事情?
答案 0 :(得分:0)
这对我有用:
HTML code:
<div id="alertMessage" class="alert alert-danger fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
</div>
Javascript代码
$(document).ready(function () {
$("input.btn").mousedown(function () {
var required = $("input.required").val();
if (required == "") {
$("#collapseOne").collapse('show');
$("#collapseTwo").collapse('hide');
$("#collapseThree").collapse('hide');
$("#alertMessage").append("<p>You have Missed Off One or More Required Fields !</p>");
}
});