Javascript 如何更改警报框的样式?
我需要更改警报框中“确定”按钮的样式Javascript 如何更改警报框的样式?,javascript,css,Javascript,Css,我需要更改警报框中“确定”按钮的样式 alertify.confirm("This is a confirm dialog.", function(){ alertify.success('Ok'); }, function(){ alertify.error('Cancel'); }); 函数show_alert(){ 警报(“你好!我是一个警报框!”); } 警报框是一个系统对象,不受CSS约束。要实现这种风格,您需要创建一个HTML元素并模拟alert
alertify.confirm("This is a confirm dialog.",
function(){
alertify.success('Ok');
},
function(){
alertify.error('Cancel');
});
函数show_alert(){
警报(“你好!我是一个警报框!”);
}
警报框是一个系统对象,不受CSS约束。要实现这种风格,您需要创建一个HTML元素并模拟alert()
功能。jQueryUI对话框为您做了大量工作,基本上如我所述
jQuery UI对话框-默认功能
$(函数(){
$(“#dialog”).dialog();
} );
这是用于显示信息的默认对话框。可以使用“x”图标移动、调整和关闭对话框窗口
样式警报()-不可能使用方框。您可以改用javascript模式覆盖。不可能。如果要自定义对话框的视觉外观,需要使用基于JS的解决方案,如。选项1。您可以使用,这对警报非常有用
选项2。如果您启动或只是加入一个基于Web应用程序的项目,界面设计可能会很好。否则这应该改变。为了开发Web2.0应用程序,您将使用动态内容、许多效果和其他内容。所有这些都很好,但是没有人考虑过如何设置JavaScript警报和确认框的样式。
这是他们的方法
创建简单的js文件名jsConfirmStyle.js。下面是简单的js代码
ie5=(document.getElementById&&document.all&&document.styleSheets)?1:0;
nn6=(document.getElementById&&!document.all)?1:0;
xConfirmStart=800;
yConfirmStart=100;
if(ie5||nn6) {
if(ie5) cs=2,th=30;
else cs=0,th=20;
document.write(
"<div id='jsconfirm'>"+
"<table>"+
"<tr><td id='jsconfirmtitle'></td></tr>"+
"<tr><td id='jsconfirmcontent'></td></tr>"+
"<tr><td id='jsconfirmbuttons'>"+
"<input id='jsconfirmleft' type='button' value='' onclick='leftJsConfirm()' onfocus='if(this.blur)this.blur()'>"+
" "+
"<input id='jsconfirmright' type='button' value='' onclick='rightJsConfirm()' onfocus='if(this.blur)this.blur()'>"+
"</td></tr>"+
"</table>"+
"</div>"
);
}
document.write("<div id='jsconfirmfade'></div>");
function leftJsConfirm() {
document.getElementById('jsconfirm').style.top=-1000;
document.location.href=leftJsConfirmUri;
}
function rightJsConfirm() {
document.getElementById('jsconfirm').style.top=-1000;
document.location.href=rightJsConfirmUri;
}
function confirmAlternative() {
if(confirm("Scipt requieres a better browser!")) document.location.href="http://www.mozilla.org";
}
leftJsConfirmUri = '';
rightJsConfirmUri = '';
/**
* Show the message/confirm box
*/
function showConfirm(confirmtitle,confirmcontent,confirmlefttext,confirmlefturi,confirmrighttext,confirmrighturi) {
document.getElementById("jsconfirmtitle").innerHTML=confirmtitle;
document.getElementById("jsconfirmcontent").innerHTML=confirmcontent;
document.getElementById("jsconfirmleft").value=confirmlefttext;
document.getElementById("jsconfirmright").value=confirmrighttext;
leftJsConfirmUri=confirmlefturi;
rightJsConfirmUri=confirmrighturi;
xConfirm=xConfirmStart, yConfirm=yConfirmStart;
if(ie5) {
document.getElementById("jsconfirm").style.left='25%';
document.getElementById("jsconfirm").style.top='35%';
}
else if(nn6) {
document.getElementById("jsconfirm").style.top='25%';
document.getElementById("jsconfirm").style.left='35%';
}
else confirmAlternative();
}
ie5=(document.getElementById&&document.all&&document.styleSheets)?1:0;
nn6=(document.getElementById&&!document.all)?1:0;
xConfirmStart=800;
yConfirmStart=100;
如果(ie5 | | nn6){
如果(ie5)cs=2,th=30;
否则cs=0,th=20;
document.write(
""+
""+
""+
""+
""+
""+
" "+
""+
""+
""+
""
);
}
文件。填写(“”);
函数leftJsConfirm(){
document.getElementById('jsconfirm').style.top=-1000;
document.location.href=leftJsConfirmUri;
}
函数rightJsConfirm(){
document.getElementById('jsconfirm').style.top=-1000;
document.location.href=rightJsConfirmUri;
}
函数confirmAlternative(){
if(确认(“Scipt需要更好的浏览器!”)document.location.href=”http://www.mozilla.org";
}
leftJsConfirmUri='';
rightJsConfirmUri='';
/**
*显示消息/确认框
*/
函数showConfirm(confirmtitle、confirmcontent、confirmlefttext、confirmlefturi、confirmrighttext、confirmrighturi){
document.getElementById(“jsconfirmtitle”).innerHTML=confirmtitle;
document.getElementById(“jsconfirmcontent”).innerHTML=confirmcontent;
document.getElementById(“jsconfirmleft”).value=confirmlefttext;
document.getElementById(“jsconfirmright”).value=confirmrighttext;
leftJsConfirmUri=confirmlefturi;
rightJsConfirmUri=confirmrighturi;
xConfirm=xConfirmStart,yConfirm=yConfirmStart;
如果(ie5){
document.getElementById(“jsconfirm”).style.left='25%';
document.getElementById(“jsconfirm”).style.top='35%';
}
若否(nn6){
document.getElementById(“jsconfirm”).style.top='25%';
document.getElementById(“jsconfirm”).style.left='35%';
}
else confirmAlternative();
}
创建简单的html文件
<html>
<head>
<title>jsConfirmSyle</title>
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<script type="text/javascript" src="jsConfirmStyle.js"></script>
<script type="text/javascript">
function confirmation() {
var answer = confirm("Wanna visit google?")
if (answer){
window.location = "http://www.google.com/";
}
}
</script>
<style type="text/css">
body {
background-color: white;
font-family: sans-serif;
}
#jsconfirm {
border-color: #c0c0c0;
border-width: 2px 4px 4px 2px;
left: 0;
margin: 0;
padding: 0;
position: absolute;
top: -1000px;
z-index: 100;
}
#jsconfirm table {
background-color: #fff;
border: 2px groove #c0c0c0;
height: 150px;
width: 300px;
}
#jsconfirmtitle {
background-color: #B0B0B0;
font-weight: bold;
height: 20px;
text-align: center;
}
#jsconfirmbuttons {
height: 50px;
text-align: center;
}
#jsconfirmbuttons input {
background-color: #E9E9CF;
color: #000000;
font-weight: bold;
width: 125px;
height: 33px;
padding-left: 20px;
}
#jsconfirmleft{
background-image: url(left.png);
}
#jsconfirmright{
background-image: url(right.png);
}
</style>
jsConfirmSyle
功能确认(){
var answer=确认(“想访问谷歌吗?”)
若有(答复){
window.location=”http://www.google.com/";
}
}
身体{
背景色:白色;
字体系列:无衬线;
}
#jsconfirm{
边框颜色:#C0;
边框宽度:2px4px4px2px;
左:0;
保证金:0;
填充:0;
位置:绝对位置;
顶部:-1000px;
z指数:100;
}
#JS确认表{
背景色:#fff;
边框:2个凹槽#C0;
高度:150像素;
宽度:300px;
}
#jsconfirmtitle{
背景色:#B0;
字体大小:粗体;
高度:20px;
文本对齐:居中;
}
#JsconfirButtons{
高度:50px;
文本对齐:居中;
}
#JSconfirButtons输入{
背景色:#E9E9CF;
颜色:#000000;
字体大小:粗体;
宽度:125px;
高度:33像素;
左侧填充:20px;
}
#jsconfirmleft{
背景图片:url(left.png);
}
#jsconfirmright{
背景图片:url(right.png);
}
我尝试使用脚本为alert()
框样式使用java脚本
。这里我使用了那些JS和CSS
请参阅此代码和JS功能
var ALERT_TITLE = "Oops!";
var ALERT_BUTTON_TEXT = "Ok";
if(document.getElementById) {
window.alert = function(txt) {
createCustomAlert(txt);
}
}
function createCustomAlert(txt) {
d = document;
if(d.getElementById("modalContainer")) return;
mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
mObj.id = "modalContainer";
mObj.style.height = d.documentElement.scrollHeight + "px";
alertObj = mObj.appendChild(d.createElement("div"));
alertObj.id = "alertBox";
if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
alertObj.style.visiblity="visible";
h1 = alertObj.appendChild(d.createElement("h1"));
h1.appendChild(d.createTextNode(ALERT_TITLE));
msg = alertObj.appendChild(d.createElement("p"));
//msg.appendChild(d.createTextNode(txt));
msg.innerHTML = txt;
btn = alertObj.appendChild(d.createElement("a"));
btn.id = "closeBtn";
btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
btn.href = "#";
btn.focus();
btn.onclick = function() { removeCustomAlert();return false; }
alertObj.style.display = "block";
}
function removeCustomAlert() {
document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}
和CSS用于警报()
#modalContainer {
background-color:rgba(0, 0, 0, 0.3);
position:absolute;
width:100%;
height:100%;
top:0px;
left:0px;
z-index:10000;
background-image:url(tp.png); /* required by MSIE to prevent actions on lower z-index elements */
}
#alertBox {
position:relative;
width:300px;
min-height:100px;
margin-top:50px;
border:1px solid #666;
background-color:#fff;
background-repeat:no-repeat;
background-position:20px 30px;
}
#modalContainer > #alertBox {
position:fixed;
}
#alertBox h1 {
margin:0;
font:bold 0.9em verdana,arial;
background-color:#3073BB;
color:#FFF;
border-bottom:1px solid #000;
padding:2px 0 2px 5px;
}
#alertBox p {
font:0.7em verdana,arial;
height:50px;
padding-left:5px;
margin-left:55px;
}
#alertBox #closeBtn {
display:block;
position:relative;
margin:5px auto;
padding:7px;
border:0 none;
width:70px;
font:0.7em verdana,arial;
text-transform:uppercase;
text-align:center;
color:#FFF;
background-color:#357EBD;
border-radius: 3px;
text-decoration:none;
}
/* unrelated styles */
#mContainer {
position:relative;
width:600px;
margin:auto;
padding:5px;
border-top:2px solid #000;
border-bottom:2px solid #000;
font:0.7em verdana,arial;
}
h1,h2 {
margin:0;
padding:4px;
font:bold 1.5em verdana;
border-bottom:1px solid #000;
}
code {
font-size:1.2em;
color:#069;
}
#credits {
position:relative;
margin:25px auto 0px auto;
width:350px;
font:0.7em verdana;
border-top:1px solid #000;
border-bottom:1px solid #000;
height:90px;
padding-top:4px;
}
#credits img {
float:left;
margin:5px 10px 5px 0px;
border:1px solid #000000;
width:80px;
height:79px;
}
.important {
background-color:#F5FCC8;
padding:2px;
}
code span {
color:green;
}
和HTML文件:
<input type="button" value = "Test the alert" onclick="alert('Alert this pages');" />
也可以查看此图像和演示结果图像
一个选项是使用,它提供了一个漂亮的警报框
alertify.confirm("This is a confirm dialog.",
function(){
alertify.success('Ok');
},
function(){
alertify.error('Cancel');
});
只需从中包含所需的库,并使用以下代码显示警报框
alertify.confirm("This is a confirm dialog.",
function(){
alertify.success('Ok');
},
function(){
alertify.error('Cancel');
});
输出将如下所示。在这里看到它的作用是
我使用,这太棒了,你会得到很多定制选项以及所有回调
您需要创建自己的警报框,如下所示:
函数jAlert(文本,自定义OK){
document.getElementById('jAlert_content')。innerHTML=text;
document.getElementById('jAlert_ok')。innerHTML=CustomOk;
document.body.style.backgroundColor=“灰色”;
document.body.style.cursor=“wait”;
}
杰勒特(“停!停!”,“好的!”)代码>
#jAlert#u table,#jAlert#th,#jAlert#td{
边框:2件纯蓝;
背景颜色:浅蓝色;
边界塌陷:塌陷;
宽度=100px;
}
#jAlert_th,#jAlert_td{
填充物:5px;
右边填充:10px;
左侧填充:10px;
}
#杰勒特{
/*定位*/
位置:固定;
/*居中*/
最高:50%;
左:50%;
利润上限:-50px;
左边距:-100px;
}
文本
正文
正文
正文
正文
T
<div id="eventContent" class="eventContent" style="display: none; border: 1px solid #005eb8; position: absolute; background: #fcf8e3; width: 30%; opacity: 1.0; padding: 4px; color: #005eb8; z-index: 2000; line-height: 1.1em;">
<a style="float: right;"><i class="fa fa-times closeEvent" aria-hidden="true"></i></a><br />
Event: <span id="eventTitle" class="eventTitle"></span><br />
Start: <span id="startTime" class="startTime"></span><br />
End: <span id="endTime" class="endTime"></span><br /><br />
</div>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
googleCalendarApiKey: 'APIkey',
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: {
googleCalendarId: '@group.calendar.google.com'
},
eventClick: function (calEvent, jsEvent, view) {
var stime = calEvent.start.format('MM/DD/YYYY, h:mm a');
var etime = calEvent.end.format('MM/DD/YYYY, h:mm a');
var eTitle = calEvent.title;
var xpos = jsEvent.pageX;
var ypos = jsEvent.pageY;
$(".eventTitle").html(eTitle);
$(".startTime").html(stime);
$(".endTime").html(etime);
$(".eventContent").css('display', 'block');
$(".eventContent").css('left', '25%');
$(".eventContent").css('top', '30%');
return false;
}
});
$(".eventContent").click(function() {
$(".eventContent").css('display', 'none');
});
});
</script>
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Something went wrong!',
footer: '<a href>Why do I have this issue?</a>'
})