JavaScript总结之鼠标划过弹出div单击出现对话框
为了满足他们的永无止境的要求,我可谓是任劳任怨啊,累断了双手,看瞎了双眼。这个是来写鼠标划过一个按钮,然后弹出一个小提示框解释,另外根据radio是否选中,判断点击后如何执行,然后执行之后再有一个确认或取消。其实部分想要的功能可以从中截取。
js代码:
<script type="text/javascript">
function sAlert_jobdel(str){
var msgw,msgh,bordercolor;
msgw=400;//提示窗口的宽度
msgh=150;//提示窗口的高度
titleheight=25 //提示窗口标题高度
bordercolor="#D3CFD0";//提示窗口的边框颜色
titlecolor="#D3CFD0";//提示窗口的标题颜色 var sWidth,sHeight;
sWidth=document.body.offsetWidth;
sHeight=screen.height; var bgObj=document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.background="#777";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity="0.6";
bgObj.style.left="0";
bgObj.style.width=sWidth + "px";
bgObj.style.height=sHeight + "px";
bgObj.style.zIndex = "10000"; var msgObj=document.createElement("div")
msgObj.setAttribute("id","msgDiv");
msgObj.setAttribute("align","center");
msgObj.style.background="white";
msgObj.style.border="5px solid " + bordercolor;
msgObj.style.position = "absolute";
msgObj.style.left = "50%";
msgObj.style.top = "50%";
msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
msgObj.style.marginLeft = "-225px" ;
msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
msgObj.style.width = msgw + "px";
msgObj.style.height =msgh + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight ="25px";
msgObj.style.zIndex = "10001"; var btn1 = document.createElement("input");
btn1.setAttribute("id","btnMks");
btn1.setAttribute("value","确定");
btn1.setAttribute("type","button");
btn1.setAttribute("width","150px");
btn1.setAttribute("height","20px");
btn1.style.paddingTop="3px";
btn1.style.paddingBottom="3px";
btn1.style.paddingLeft="8px";
btn1.style.paddingRight="8px";
btn1.style.marginTop="40px";
btn1.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
btn1.style.opacity="0.75";
btn1.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
btn1.style.cursor="pointer";
btn1.onclick=function(){
document.body.removeChild(bgObj);
document.getElementById("msgDiv").removeChild(title);
document.body.removeChild(msgObj);
} var title=document.createElement("h4");
title.setAttribute("id","msgTitle");
title.setAttribute("align","right");
title.style.margin="0";
title.style.padding="3px";
title.style.background=bordercolor;
title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
title.style.opacity="0.75";
title.style.border="1px solid " + bordercolor;
title.style.height="18px";
title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
title.style.color="white";
title.style.cursor="pointer";
title.innerHTML="关闭";
title.onclick=function(){
document.body.removeChild(bgObj);
document.getElementById("msgDiv").removeChild(title);
document.body.removeChild(msgObj);
}
var bool=false;
for(i=0;i<document.getElementsByName("job_item").length;i++){
if(document.getElementsByName("job_item").item(i).checked){
bool=true;
}}
if(bool==false){
document.body.appendChild(bgObj);
document.body.appendChild(msgObj);
document.getElementById("msgDiv").appendChild(title);
var txt=document.createElement("p");
txt.style.margin="1em 0"
txt.setAttribute("id","msgTxt");
txt.style.color="#000"
txt.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif"
txt.innerHTML=str;
document.getElementById("msgDiv").appendChild(txt);
document.getElementById("msgDiv").appendChild(btn1);
}else{
if(window.confirm('删除是不可恢复的,你确定要删除吗?')){
/*alert("确定");*/
return true;
}else{
/* alert("取消");*/
return false;
} }
} </script>
这段js代码实现了弹出提示框,还有再次确认框。
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function(){
$("#popup_submit1").mouseover(function(){
$('#overflow1').delay(400).show('fast');
})
$("#popup_submit1").mouseout(function(){
$('#overflow1').hide('fast');
})
$("#popup_submit2").mouseover(function(){
$('#overflow2').delay(400).show('fast');
})
$("#popup_submit2").mouseout(function(){
$('#overflow2').hide('fast');
})
})
</script>
这段代码是鼠标划过显示下拉框。需要注意下的就是这里有一个延时。是为了避免鼠标无意划过多次,弹出多次。
HTML代码:
<form>
<input type="radio" name="job_item" />
作业1<br />
<input type="radio" name="job_item" />
作业2<br />
<input type="radio" name="job_item" />
作业3<br />
<input type="radio" name="job_item" />
作业4<br />
<br />
<br />
<br />
<br />
<span style="width:200px;">
<input style="width:100px;" id="popup_submit1" type="button" value="删除" onclick="sAlert_jobdel('请在作业列表中选择一个作业');">
<div class="tip1" id="overflow1">
<div class="arrow"></div>
<div class="wrap">
<div class="content">
<p>选中一个作业后删除</p>
</div>
</div>
</div>
</span> <span style="margin-left:20px; width:200px;">
<input style="width:100px;" id="popup_submit2" type="reset" value="重置" >
<div class="tip1" id="overflow2">
<div class="arrow"></div>
<div class="wrap">
<div class="content">
<p>取消radio的选中状态</p>
</div>
</div>
</div>
</span>
</form>
将按钮放在一个form里,可以形成一个像组一样的东西,这样input一个type为reset的重置就可以将选中的radio去掉。
CSS代码:
<style type="text/css">
.tip1 {
position: absolute;
z-index:;
display: none;
margin-top: 30px;
}
.tip1 > div.arrow {
background: url(../assets/inline_help_arrow.png);
position: absolute;
width: 30px;
height: 18px;
background-repeat: no-repeat;
right: 80px;
top:;
}
.tip1 > .wrap {
-moz-box-shadow: 2px 2px 10px rgba(0, 0, 10, 0.3), inset 0 1px 2px white;
-o-box-shadow: 2px 2px 10px rgba(0, 0, 10, 0.3), inset 0 1px 2px white;
-webkit-box-shadow: 2px 2px 10px rgba(0, 0, 10, 0.3), inset 0 1px 2px white;
box-shadow: 2px 2px 10px rgba(0, 0, 10, 0.3), inset 0 1px 2px white;
-moz-border-radius: 3px;
/* Gecko */
-webkit-border-radius: 3px;
/* Webkit */
-khtml-border-radius: 3px;
/* Konqueror */
border-radius: 3px;
/* CSS3 */
border: 1px solid #bbb;
border-bottom-color: #aaa;
border-right-color: #aaa;
background: #fff;
background-image: -moz-linear-gradient(#f8f8f8, #ededef);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #f8f8f8), color-stop(1, #ededef));
background-image: -webkit-linear-gradient(#f8f8f8, #ededef);
background-image: -o-linear-gradient(#f8f8f8, #ededef);
background-image: -ms-linear-gradient(top, #f8f8f8, #ededef);
background-image: linear-gradient(top, #f8f8f8, #ededef);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f8f8f8', endColorstr='#ededef');
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#f8f8f8', endColorstr='#ededef')";
padding: 5px 5px;
width: 150px;
color: #333;
font-weight: normal;
opacity: 0.7;
filter: alpha(opacity=70);/* IE 透明度70%*/
-moz-opacity: .7;/* Moz + FF 透明度70%*/
}
.tip1 > .wrap > .content {
margin-top: 5px;
padding: 0 10px 0 10px;
background: #fff;
border: 1px solid #cfcfcf;
max-height: 400px;
overflow-y: auto;
-moz-box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.1);
-o-box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.1);
box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.1);
}
.tip1 > .wrap .content p {
color: #000;
}
.tip1 > .wrap h3 {
text-align: center;
padding-top: 10px;
padding-left: 5px;
margin:;
color: #000;
font-weight:;
font-size: 14px;
}
.tip1 > .wrap h3:first-child {
padding-top: 5px;
}
.tip1 > .wrap h4 {
color: #fff;
font-style: italic;
}
</style>
将这些部分合到一个页面里面是可以完美运行起来的。
有空来记录一下确实不错。发上来之前就发现了一出逻辑错误。我用for循环来检测每一个radio。但是也把画弹出框的语句放到循环里了,最后造成的效果是画了好几次。以后这习惯得好好保持啊。
意见建议欢迎提出。
JavaScript总结之鼠标划过弹出div单击出现对话框的更多相关文章
- 工作当中实际运用(3)——js原生实现鼠标点击弹出div层 在点击隐藏
function onmou(){ var divs=document.getElementById('kefuDV');//获取到你要操作的div if (divs.style.display==& ...
- Jquery hover鼠标经过时弹出div动态提示语
一.效果图 二.需求描述 1.鼠标经过table每一行时,弹出div动态提示语: 2.div弹出层的位置随鼠标位置的变化而变化: 3.鼠标离开table或获取的动态提示语为空时,div弹出层消失. 下 ...
- JavaScript鼠标事件,点击鼠标右键,弹出div
document.oncontextmenu = function(){return false}; //禁止鼠标右键菜单显示 var res = document.getElementById('b ...
- ECshop鼠标划过弹出 微信扫一扫代码
效果如上图 安装步骤:1,将以下代码放到page_header.lbi里 <div class="f_l"><a href="../index.p ...
- 鼠标滑过弹出jquery在线客服
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【转】javascript入门系列演示·三种弹出对话框的用法实例
对话框有三种 1:只是提醒,不能对脚本产生任何改变: 2:一般用于确认,返回 true 或者 false ,所以可以轻松用于 if...else...判断 3: 一个带输入的对话框,可以返回用户填入的 ...
- 基于jQuery鼠标点击弹出登陆框效果
基于jQuery鼠标点击弹出登陆框效果.这是一款扁平样式风格的jQuery弹出层登陆框特效.效果图如下: 在线预览 源码下载 实现的代码. html代码: <input type=" ...
- 联想E440问题:点击鼠标时,弹出“无法连接synaptics定点装置驱动程序”错误
笔记本:Levono E440 问题描述: 在控制面板中,点击鼠标时,弹出“无法连接synaptics定点装置驱动程序”错误,如何解决? 即使在安装联想的驱动后,也没办法解决 解决步骤: 1. ...
- javascript入门系列演示·三种弹出对话框的用法实例
对话框有三种 1:只是提醒,不能对脚本产生任何改变: 2:一般用于确认,返回 true 或者 false ,所以可以轻松用于 if...else...判断 3: 一个带输入的对话框,可以返回用户填入的 ...
随机推荐
- SQL语句函数详解__sql聚合函数
函数是一种有零个或多个参数并且有一个返回值的程序.在SQL中Oracle内建了一系列函数,这些函数都可被称为SQL或PL/SQL语句,函数主要分为两大类:单行函数.组函数 本文将讨论如何使用单行函数及 ...
- iOS FMDB
FMDB FMDB概述 什么是FMDB * FMDB是iOS平台的SQLite数据库框架 * FMDB以OC的方式封装了SQLite的C语言API FMDB的优点 * 使用起来更加面向对象,省去了很多 ...
- MySql优化-你的SQL命中索引了吗
在项目开发中SQL是必不可少的,表索也一样.这些SQL的运行性能不知道吗?有多少是命中了索引的?命中哪个索引?索引中有哪个是无效索引?这些无效索引是否会影响系统的性能?带着这些问题我们一起来学习一下. ...
- c#中的数据类型简介(委托)
c#中的数据类型简介(委托) 什么是委托? 委托是一种类型,它封装了一类方法,这些方法具有相同的方法签名(signature).定义听起来有点拗口,首先可以确定委托是一种数据类型,那么什么是方法签名, ...
- .NET c# 串口通信
这段时间做了一个和硬件设备通信的小项目,涉及到扫描头.输送线.称重机.贴标机等硬件.和各设备之间通信使用的是串口或网络(Socket)的方式.扫描头和贴标机使用的网络通信,输送线和称重机使用的是串口通 ...
- Java 基础之 static 静态
static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念. 被static修饰的成员变量和成员方法独立于该类的任何 ...
- K - Digital Roots(第二季水)
Description The digital root of a positive integer is found by summing the digits of the integer. If ...
- 2015.4.16-C#中ref和out的区别
如图: 输出结果是: 上面显示的是 ref 只是地址传递,所以最初改变的也只是地址,但是如果 在给其赋值,值会随之改变;如果 在方法内直接赋值,那么输出的结果 就是现在的值,之后 ...
- Arcgis Engine 添加一个Symbol符号样式步骤
public static void DrawPictureMarkerSymbol(IGlobe globe, String layerName) { //添加一个图层 ESRI.ArcGIS.Ca ...
- 理解javascript 回调函数
##回调函数定义 百度百科:回调函数 回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用为调用它所指向的函数时,我们就说这是回调函数.回调函数不 ...