window.confirm用法

1.如何在ASP.NET中获得JavaScript弹出窗口Yes/No值
The sample code?is on the most frequently asked query on "How to get the confirmation of Yes/No from a javascript pop up and display the value on the page using ASP.NET"?
  • Create a webpage main.aspx
  • Drag and drop a?hidden control and <asp:button> control on the web form.

Step 1. main.aspx.vb

Write the following code on page load event

Button1.Attributes.Add("onclick", "getMessage()")

Step 2.In main.aspx

Add the client side-script block

<SCRIPT language=javascript>
 function getMessage()
 {
 var ans;
 ans=window.confirm('Is it your confirmation.....?');
 //alert (ans);                      
 if (ans==true)
  {
    //alert('Yes');
    document.Form1.hdnbox.value='Yes';
   }
 else
 {
    //alert('No');
    document.Form1.hdnbox.value='No';}

 }
</SCRIPT>

Step 3. main.aspx.vb

To display the value of the value selected by the user in the pop up write the following code

Response.Write(Request.Form("hdnbox"))

2.window.confirm 的默认按钮是"确定" "取消"

怎么能改成别的 比如 "是" "否" ???

改不了的,
不过可以用window.showModalDialog()来做

采用VBscript可以得到相同的效果

<script language="vbscript">
sub hello()
MsgBox"这是一个测试代码。可以根据需要修。",vbDefaultbutton2+vbOkCancel,"代码测试"
end sub
</script>
<body οndblclick="hello()">

可以使用CSS和JavaScript来美化window.confirm弹窗。 首先,使用CSS样式来调整窗口的样式,如下所示: ```css /* 遮罩层 */ .confirm-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: 9999; } /* 弹窗容器 */ .confirm-container { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); z-index: 10000; } /* 按钮样式 */ .confirm-btn { display: inline-block; padding: 10px 20px; background: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer; transition: all 0.3s ease; } .confirm-btn:hover { background: #0062cc; } ``` 然后,使用JavaScript来替换默认的window.confirm方法,如下所示: ```javascript // 替换 window.confirm 方法 window.confirm = function (message) { // 创建遮罩层 var overlay = document.createElement('div'); overlay.classList.add('confirm-overlay'); // 创建弹窗容器 var container = document.createElement('div'); container.classList.add('confirm-container'); // 创建提示信息 var messageEl = document.createElement('p'); messageEl.innerText = message; container.appendChild(messageEl); // 创建按钮 var confirmBtn = document.createElement('button'); confirmBtn.classList.add('confirm-btn'); confirmBtn.innerText = '确认'; confirmBtn.addEventListener('click', function () { overlay.remove(); // 移除遮罩层 return true; // 确认后返回true }); container.appendChild(confirmBtn); var cancelBtn = document.createElement('button'); cancelBtn.classList.add('confirm-btn'); cancelBtn.innerText = '取消'; cancelBtn.addEventListener('click', function () { overlay.remove(); // 移除遮罩层 return false; // 取消后返回false }); container.appendChild(cancelBtn); // 添加弹窗容器到遮罩层 overlay.appendChild(container); // 添加遮罩层到页面 document.body.appendChild(overlay); }; ``` 这样,调用window.confirm方法时,就会出现美化后的弹窗了。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值