如何在javascript中创建是/否对话框? [英] How to create yes/no dialog in javascript?

查看:81
本文介绍了如何在javascript中创建是/否对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能创建一个提示用户按是或否的javascript弹出窗口。我想要类似于Confirm()的东西,但我希望消息说是/否而不是确定/取消。


我也知道这可以通过vbscript实现,但我不想使用vbscript,因为它只是IE浏览器。


有没有人知道这个问题的解决方案(我不想改变这个问题,以便让用户输入确定/取消)


有没有办法创建这种弹出窗口?

我需要帮助!

Hi, how can I create a javascript popup that prompts users to press yes or no. I want something similar to Confirm(), but I want the message to say "yes/no" instead of "ok/cancel".

Also I know this is possible through vbscript, but I don''t want to use vbscript since it is IE only.

Does anyone know a solution to this problem (I don''t want to change the question in order to make it sense that the user enter "ok/cancel" )

Is there a way to create this kind of popup?
I need help please!

推荐答案

嗨...


不幸的是没有在js-confirm-dialog中设置按钮文本的方法。但你可以为自己创建一个html / css ...


亲切的问候
hi ...

unfortunatly there is no way to set the text of the buttons in the js-confirm-dialog. but you may create one with html/css for yourself ...

kind regards



嗨...


不幸的是,没有办法在js-confirm-dialog中设置按钮的文本。但你可以为自己创建一个html / css ...


亲切问候
hi ...

unfortunatly there is no way to set the text of the buttons in the js-confirm-dialog. but you may create one with html/css for yourself ...

kind regards



您好,感谢您的回答,你能给我一个链接或告诉我如何用html / css创建一个吗?

Hi, thanks for your answer, Can you please give me a link or show me how to create one with html/css ?


heya ...


快速写了一个;)...应该显示可能性......它还没有真正准备好或真正的酷,但它的工作正确...可能我会在下次工作...为了好玩;)).. 。


[HTML]< html>

< head>

< script>

函数CUST_CONFIRM(params){

this.ok = typeof params.ok!=''undefined''? params.ok

:''好'';

this.cancel = typeof params.cancel!=''undefined''?

params.cancel:''取消'';

this.msg = typeof params.message!=''undefined''?

params.message:'''';


ok_cb = typeof params.ok_cb!=''undefined''? params.ok_cb

:function(){};

cncl_cb = typeof params.cancel_cb!=''undefined''?

params.cancel_cb:function(){};


this.ok_cb = function(){

var cp = document .getElementById(''cust_confirm_popup'');

document.lastChild.lastChild.removeChild(cp);


ok_cb();

};


this.cncl_cb = function(){

var cp = document.getElementById(''cust_confirm_popup'');

document.lastChild.lastChild.removeChild(cp);


cncl_cb();

};


this._build_dom();

}


CUST_CONFIRM.prototype._build_dom = function(){

var confirm_container = document.createElement(''div'');


confirm_container.id =' cust_confirm_popup'';

confirm_container.style [''z-index''] =''1'';

confirm_container.style.position =''absolute'' ;

confirm_container.style.left =''0px'';

confirm_container.style.top =''50%'';

confirm_container.style.width ='''100%'';


var container = document.createElement(''div'');


container.style [''z-index''] ='''''';

container.style.marginLeft ='' - 50px'';

容器.style.position =''absolute'';

container.style.border =''1px solid black'';

container.style.color =''red '';

container.style.left =''50%'';

container.style.top ='' - 10px'';

container.style.padding ='''5px 5px 5px 5px'';


container.innerHTML = this.msg +''< br />< div>< / div>'';


var ok_btn = document.createElement (''输入'');


ok_btn.type =''按钮'';

ok_btn.value = this.ok;

ok_btn.onclick = this.ok_cb;


container.lastChild.appendChild(ok_btn);


var cncl_btn = document。 createElement(''input'');


cncl_btn.type =''button'';

cncl_btn.value = this.cancel;

cncl_btn.onclick = this.cncl_cb;


container.lastChild.appendChild(cncl_btn);


co nfirm_container.appendChild(container);

document.lastChild.lastChild.appendChild(confirm_c ontainer);

}


function custom_confirm (参数){

var confirm = new CUST_CONFIRM(params);

}


函数do_ok(){

alert(''ok'');

}


函数do_cancel(){

alert( ''取消'');

}

< / script>

< / head>

< body>

< input type =" button" value =" open custom confirm"

onclick ="

var params = {

ok:''是'',

取消:''不'',

消息:''你确定吗?'',

ok_cb:do_ok,

cancel_cb:do_cancel

};

custom_confirm(params);

" />

< / body>

< / html> [/ HTML]


亲切的问候
heya ...

quickly wrote one ;) ... that should show the possibilities ... its not really ready or real cool yet but it works correct ... may be i''ll work at it the next time ... for fun ;)) ...

[HTML]<html>
<head>
<script>
function CUST_CONFIRM(params) {
this.ok = typeof params.ok != ''undefined'' ? params.ok
: ''Ok'';
this.cancel = typeof params.cancel != ''undefined'' ?
params.cancel : ''Cancel'';
this.msg = typeof params.message != ''undefined'' ?
params.message : '''';

ok_cb = typeof params.ok_cb != ''undefined'' ? params.ok_cb
: function() {};
cncl_cb = typeof params.cancel_cb != ''undefined'' ?
params.cancel_cb : function() {};

this.ok_cb = function() {
var cp = document.getElementById(''cust_confirm_popup'');
document.lastChild.lastChild.removeChild(cp);

ok_cb();
};

this.cncl_cb = function() {
var cp = document.getElementById(''cust_confirm_popup'');
document.lastChild.lastChild.removeChild(cp);

cncl_cb();
};

this._build_dom();
}

CUST_CONFIRM.prototype._build_dom = function() {
var confirm_container = document.createElement(''div'');

confirm_container.id = ''cust_confirm_popup'';
confirm_container.style[''z-index''] = ''1'';
confirm_container.style.position = ''absolute'';
confirm_container.style.left = ''0px'';
confirm_container.style.top = ''50%'';
confirm_container.style.width = ''100%'';

var container = document.createElement(''div'');

container.style[''z-index''] = ''2'';
container.style.marginLeft = ''-50px'';
container.style.position = ''absolute'';
container.style.border = ''1px solid black'';
container.style.color = ''red'';
container.style.left = ''50%'';
container.style.top = ''-10px'';
container.style.padding = ''5px 5px 5px 5px'';

container.innerHTML = this.msg + ''<br/><div></div>'';

var ok_btn = document.createElement(''input'');

ok_btn.type = ''button'';
ok_btn.value = this.ok;
ok_btn.onclick = this.ok_cb;

container.lastChild.appendChild(ok_btn);

var cncl_btn = document.createElement(''input'');

cncl_btn.type = ''button'';
cncl_btn.value = this.cancel;
cncl_btn.onclick = this.cncl_cb;

container.lastChild.appendChild(cncl_btn);

confirm_container.appendChild(container);
document.lastChild.lastChild.appendChild(confirm_c ontainer);
}

function custom_confirm(params) {
var confirm = new CUST_CONFIRM(params);
}

function do_ok() {
alert(''ok'');
}

function do_cancel() {
alert(''cancel'');
}
</script>
</head>
<body>
<input type="button" value="open custom confirm"
onclick="
var params = {
ok: ''Yes'',
cancel: ''No'',
message: ''Are you sure?'',
ok_cb: do_ok,
cancel_cb: do_cancel
};
custom_confirm(params);
"/>
</body>
</html>[/HTML]

kind regards


这篇关于如何在javascript中创建是/否对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆