从条件javascript函数返回一个自定义对话框
returning a custom dialog box from a conditional javascript function
这是我的javascript函数,用于检查上传的文件是否为图像格式类型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 dig copy may be in a different file format! Formats allowed are " + _validFileExtensions.join(", "));
return false;
}
}
}
}
return true;
}
下面的代码给出了一个我想调用的自定义对话框,而不是默认的
框<style>
#white-background{
display: none;
width: 100%;
height: 100%;
position: fixed;
top: 0px;
left: 0px;
background-color: #fefefe;
opacity: 0.7;
z-index: 9999;
}
#dlgbox{
/*initially dialog box is hidden*/
display: none;
position: fixed;
width: 480px;
z-index: 9999;
border-radius: 10px;
background-color: #7c7d7e;
}
#dlg-header{
background-color:aliceblue;
color: white;
font-size: 20px;
padding: 10px;
margin: 10px 10px 0px 10px;
}
#dlg-body{
background-color: white;
color: black;
font-size: 14px;
padding: 10px;
margin: 0px 10px 0px 10px;
}
#dlg-footer{
background-color: #f2f2f2;
text-align: right;
padding: 10px;
margin: 0px 10px 10px 10px;
}
#dlg-footer button{
background-color: grey;
color: white;
padding: 5px;
border: 0px;
}
</style>
</head>
<body>
<!-- dialog box -->
<div id="white-background">
</div>
<div id="dlgbox">
<div id="dlg-header"></div>
<div id="dlg-body">Sorry a dig copy may be in a different file format! Formats allowed are ".jpg", ".jpeg", ".bmp", ".gif", ".png"</div>
<div id="dlg-footer">
<button onclick="dlgLogin()">Ok</button>
</div>
</div>
<!-- rest of the page -->
<h1>Dialog Box Demo</h1>
<p>This is a dialog box example.</p>
<p>Feel free to experiment with the code.</p>
<p>Click the button below to see the dialog box.</p>
<button onclick="showDialog()">Click Me!</button>
<!-- script of dialog -->
<script>
function dlgLogin(){
var whitebg = document.getElementById("white-background");
var dlg = document.getElementById("dlgbox");
whitebg.style.display = "none";
dlg.style.display = "none";
}
function showDialog(){
var whitebg = document.getElementById("white-background");
var dlg = document.getElementById("dlgbox");
whitebg.style.display = "block";
dlg.style.display = "block";
var winWidth = window.innerWidth;
var winHeight = window.innerHeight;
dlg.style.left = (winWidth/2) - 480/2 + "px";
dlg.style.top = "150px";
}
</script>
请帮助我将第二个代码集成到第一个代码中,以便我可以返回自定义对话框,而不是默认的警报框
你可以在这里找到你的答案如何改变警告框的样式
The alert box is a system object, and not subject to CSS. To do this style of thing you would need to create an HTML element and mimic the alert() functionality. The jQuery UI Modal box does a lot of the work for you, working basically as I have described: Link.
相关文章:
- 从HTTPGET返回一个自定义对象列表,以便在Angular 2应用程序中使用
- SuiteScript2.0-包括一个自定义文件
- Wordpress在播放器旁边播放一个自定义的下载按钮,而不是下载
- SuiteScript:如何有一个自定义的数据字段来从数据库加载信息
- 如何使用其他自定义指令中的元素标记作为另一个自定义指令的模板
- 调用另一个自定义指令的角度自定义指令
- 我想做一个自定义的dojo JsonRest商店,有一部分我没有'我不明白
- 如何调用另一个js文件中的函数或触发一个自定义事件,该事件将参数作为Jquery中的数据对象传递
- 我想知道如何创建一个自定义对话框,当点击按钮时会弹出
- 在brunc.io中创建一个自定义JS目录
- 如何使用Angular 1.5组件将属性求值为字符串,这是一个自定义函数
- 为谷歌工作表创建一个自定义函数
- Vaadin:调用一个自定义的JavaScript函数
- Tinymce-创建一个自定义的javascript保存按钮
- Wordpress创建一个自定义休息服务
- 如何在Angular 1.3.6上创建一个自定义过滤器来搜索嵌套数组
- 当我点击一个asp表元素时,我如何制作一个自定义弹出窗口
- 我对javascript中的一个自定义函数感到困惑,该函数将对象作为参数获取
- 为什么我们必须注册一个自定义元素
- 导入 serval WebComponent 时,上一个自定义元素被下一个元素覆盖