求助!!!!!!
如题,有没有人做过网页上类似于alert的对话框!
是柱塞式的。
详细的情况,我给大家打个比方!!
function ex(){
alert("系统阻塞式的alert");
document.getElementById("username").value="帮帮我";
}
如上述例子,用系统定义的alert函数是阻塞式的! 必须关闭系统弹出的alert后,才会赋值!!现在想要实现的就是这种阻塞式的对话框。。
function ex2(){
myAlert("自定义阻塞式的alert");
document.getElementById("username").value="帮帮我";
}ps:已经写出模态的对话框!但是,他会在不关闭对话框的同时继续赋值!求高手帮忙,或给出代码,思路,皆可!!
如题,有没有人做过网页上类似于alert的对话框!
是柱塞式的。
详细的情况,我给大家打个比方!!
function ex(){
alert("系统阻塞式的alert");
document.getElementById("username").value="帮帮我";
}
如上述例子,用系统定义的alert函数是阻塞式的! 必须关闭系统弹出的alert后,才会赋值!!现在想要实现的就是这种阻塞式的对话框。。
function ex2(){
myAlert("自定义阻塞式的alert");
document.getElementById("username").value="帮帮我";
}ps:已经写出模态的对话框!但是,他会在不关闭对话框的同时继续赋值!求高手帮忙,或给出代码,思路,皆可!!
解决方案 »
- 怎么用js获得struts2标签中的值
- 火狐下面有类似ActiveXObject("Scripting.Dictionary")的方法吗
- js给文本框赋值(急)
- 用window.showModelDialog返回值给父页面时报undifine脚本错误
- mailto
- ExtJs 中怎么添加一行计算总和? ####################### 100% 结贴,坐等高手
- 怎样屏蔽IE工具栏里面的后退和刷新按钮!?
- 关于下载确认框
- html中可以让一个控件写满位后自动跳到TAG键所对应的下一个控件上吗?
- bootstrap,使用模态框传递不同参数显示不同的分类内容,但是模态框不刷新,何解?
- js 深度clone对象
- js操作文件:怎么用FileSystemObject得到文件夹中文件的个数啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1、你可以调整代码结果,让对话框关闭后,再执行赋值
2、你可以用setInterval()不断检验对话框是否关闭,一旦关闭,再执行赋值
var a = myAlert("自定义阻塞式的alert");
var timer = setInterval(function(){
if(a.hasClose){
document.getElementById("username").value="帮帮我";
clearInterval(timer);
}
},500);
document.getElementById('sure').onclick = function(){
document.getElementById("username").value="帮帮我";
}
但是情况有些可能是这样的。。
如:你要同时验证2个text文本域。。
结果2个都验证通不过!
你再验证的时候。不会一个一点的验证吧。肯定是放在一个function验证;也就是在同一段代码中验证。
这种情况就会,弹出一个对话框,然后你点了确定,然后再弹出一个对话框。!你return了也会弹出来。因为代码已经执行了!
dgStatu=false;
myAlert(txt);//这里是我自己封装的alert
var timer = setInterval(function(){
if(dgStatu){
alert("chenggong!");
clearInterval(timer);
}
},10);//这里的意思是阻塞吗?会产生效果么?
}function show2Alert(){
showMyAlert('hello');
showMyAlert('hello1';
}上面代码是我测得7楼朋友的方法。用firebug调试。show2Alert这个方法中两个
showMyAlert()方法都会执行。一次性弹出2个对话框
而且楼主你想阻塞线程的做法是行不通的,因为根本没有API可以做到
其实alert函数的阻塞只是其中一种实现方法。你也可以自行模拟一种类似阻塞的行为,就和4楼5楼说的类似,
例如你的要在关闭窗口后执行的代码可以写在一个函数里,关闭窗口后执行这个函数或这段代码就可以了。加上貌似你是要在验证页面后弹出窗口。那么验证代码也可以写成一个函数。如下:
function validatin(){
// Check all textbox valid or not. return true or false.
}function afterCloseWindow(){
// Do something
}//你的myAlert再增加一个参数,传入一个function,如下
function myAlert(text, fn){
// 你的代码,当点击确认或者关闭弹出窗口的时候就运行fn函数
}//那你的ex2方法就变成了
function ex2(){
myAlert("自定义阻塞式的alert",afterCloseWindow);
}
//或者
function ex2() {
myAlert("自定义阻塞式的alert",function(){
document.getElementById("username").value="帮帮我";
})
}你看这样行不行?
系统的alert是有它引擎的接口做的,也就是由源码实现,我们是没办法调用的
<html>
<head>
<title> New Document </title>
<style>
div{
margin: 10px;
}
#tip{
color: red;
}
.hide{
display: none;
}
#myalert{
position: absolute;
top: 0;
left: 0;
z-index: 1000;
width: 100%;
height: 100%;
background-red: gray;
}
#myalert div{
width:200px;
height: 100px;
border: 1px solid blue;
position: absolute;
top:100px;
left: 500px;
}
form.highlight{
border: 1px solid red;
}
</style>
</head>
<body>
<form>
<div id="tip" class="hide">不能为空</div>
<div>
<input id="input_1" type="text" value=""/>
<font color="red" class="hide">不能为空</font>
</div>
<div>
<input id="input_2" type="text" value=""/>
<font color="red" class="hide">不能为空</font>
</div>
<div>
<input id="input_3" type="text" value=""/>
<font color="red" class="hide">不能为空</font>
</div>
<div>
<input id="input_4" type="text" value=""/>
<font color="red" class="hide">不能为空</font>
</div>
<input id="btn" type="button" value="submit"/>
</form>
<div id="myalert" class="hide">
<div>
<p>不能为空</p>
<button>确定</button>
</div>
</div>
<script>
var form = document.getElementsByTagName('form')[0];
var inputboxs = form.getElementsByTagName('input');
var state = false;
var myalert = document.getElementById('myalert');
myalert.height = document.body.clientHeight;
alert(myalert.height);
document.getElementById('btn').onclick = function(){
for(var i in inputboxs){
var input = inputboxs[i];
if(input.type === 'text'){
if(input.value === '' || typeof input.value === 'undefined'){
state = true;
var nextElem = input.nextSibling;
while(nextElem){
if(nextElem.tagName === 'FONT'){
nextElem.className = '';
break;
}else{
nextElem = nextElem.nextSibling;
}
}
}
}
}
if(state){
myalert.className = '';
}
}
myalert.getElementsByTagName('button')[0].onclick = function(){
document.getElementById('tip').className = '';
form.className = 'highlight';
myalert.className = 'hide';
}
</script>
</body>
</html>
<html>
<head>
<title> New Document </title>
<style>
div{
margin: 10px;
}
#tip{
color: red;
}
.hide{
display: none;
}
#myalert{
position: absolute;
top: 0;
left: 0;
z-index: 1000;
width: 100%;
height: 100%;
background-color: gray;
}
#myalert div{
width:200px;
height: 100px;
border: 1px solid blue;
position: absolute;
top:100px;
left: 500px;
}
form.highlight{
border: 1px solid red;
}
</style>
</head>
<body>
<form>
<div id="tip" class="hide">红色部分不能为空</div>
<div>
<input id="input_1" type="text" value=""/>
</div>
<div>
<input id="input_2" type="text" value=""/>
</div>
<div>
<input id="input_3" type="text" value=""/>
</div>
<div>
<input id="input_4" type="text" value=""/>
</div>
<input id="btn" type="button" value="submit"/>
</form>
<div id="myalert" class="hide">
<div>
<p>不能为空</p>
<button>确定</button>
</div>
</div>
<script>
var form = document.getElementsByTagName('form')[0];
var inputboxs = form.getElementsByTagName('input');
var state = false;
var myalert = document.getElementById('myalert');
myalert.height = document.body.clientHeight;
document.getElementById('btn').onclick = function(){
for(var i in inputboxs){
var input = inputboxs[i];
if(input.type === 'text'){
if(input.value === '' || typeof input.value === 'undefined'){
state = true;
input.style.backgroundColor = 'red';
var nextElem = input.nextSibling;
}
}
}
if(state){
myalert.className = '';
}
}
myalert.getElementsByTagName('button')[0].onclick = function(){
document.getElementById('tip').className = '';
form.className = 'highlight';
myalert.className = 'hide';
}
</script>
</body>
</html>
但是目前项目已经写到一大半了。很多都是统一用alert框弹出错误的js验证信息!(不止登录,注册)很多地方。。
然后昨天老板看到项目效果就冒了一句,这系统的对话框太丑了!能不能改成其他地方的对话框(lhgdialog库的效果);
当时我就着了。因为自定义的对话框没有阻塞的功能(能模态!但不能阻塞)!故而上来发贴求助!
还是谢谢您啊!
谢谢您!!目前主要是不想改动原有代码!
改动代价太大!!目前就想实现一个类似系统alert有阻塞功能的myAlert。。