我写了一个javascript函数,我想在jquery警告框中返回一条消息!目前该消息是在一个javascript警告框中返回的,这似乎对我的程序没什么吸引力!我对jquery不熟悉所以请帮助我!
我的程序代码如下,用于识别上传的文件是否是图像格式!如果它不是图像格式1,则会返回一个警告框,并显示错误消息!(我想将此警报设为一个框jquery 1)请帮帮我
var _validFileExtensions = [".jpg", ".jpeg", ".bmp", ".gif", ".png"];
function Validate(oForm) {
var arrInputs = oForm.getElementsByTagName("input");
for (var i = 0; i < arrInputs.length; i++) {
var oInput = arrInputs[i];
if (oInput.type == "file") {
var sFileName = oInput.value;
if (sFileName.length > 0) {
var blnValid = false;
for (var j = 0; j < _validFileExtensions.length; j++) {
var sCurExtension = _validFileExtensions[j];
if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) {
blnValid = true;
break;
}
}
if (!blnValid) {
alert("Sorry a copy may be in a different file format! Formats allowed are " + _validFileExtensions.join(", "));
return false;
}
}
}
}
return true;
}
答案 0 :(得分:1)
<!DOCTYPE html>
<head>
<title>jQuery Alerts</title>
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.ui.draggable.js" type="text/javascript"></script>
<script src="jquery.alerts.js" type="text/javascript"></script>
<link href="jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" />
<!-- Example script -->
<script type="text/javascript">
$(document).ready( function() {
$("#basic_button").click( function() {
jAlert('Example of a basic alert box in jquery', 'jquery basic alert box');
});
});
</script>
</head>
<body>
<p>
<input id="basic_button" type="button" value="Show Basic Alert" />
</p>
</body>
</html>
您可以下载相关性文件here