gpt4 book ai didi

c# - 如何在 ASP .NET MVC 5 View 中重命名 confirm() 按钮?

转载 作者:行者123 更新时间:2023-11-28 02:45:51 25 4
gpt4 key购买 nike

我在 View 中编写脚本标记函数。当我单击 View 中的菜单项时调用此函数。

我想重命名 Java 脚本 confirm() 按钮。我怎样才能做到这一点 ?我不知道如何为这种情况编写 Java 脚本代码。

Result Image

我按照下面的代码

<script type="text/javascript">
function myFunction() {
var x;
if (confirm("Press a button") == true) {
x = "You pressed Cancel";
} else {
x = "You pressed OK";
}
}
</script>
<li><a><span class="glyphicon glyphicon-log-in" onclick="myFunction()"> </span> Exit</a></li>

最佳答案

回答

您无法控制 confirm() 或 alert() Javascript 对话框的外观,因为它们是 native 的,因此它们的设计基于操作系统/浏览器。

你可以做什么:

  • 自己的对话
  • 扩展/插件
  • 使用现有的对话框js

构建自己的点击元素的方法

document.querySelector('#okLI').addEventListener('click', handleClick);
document.querySelector('#cancelLI').addEventListener('click', handleClick);

function handleClick(e){
var target = e.target;
var clickType = target.getAttribute("click-type");
if(clickType > 0)
console.log("CLICKED OK");
if(clickType < 0)
console.log("CLICKED CANCEL");
}

document.querySelector('#ok').addEventListener('click', clickButton);
document.querySelector('#cancel').addEventListener('click', clickButton);

function clickButton(e){
var button = e.target;
var buttonType = button.getAttribute("button-type");
if(buttonType > 0)
console.log("CLICKED OK");
if(buttonType < 0)
console.log("CLICKED CANCEL");
}
<ul>
<li id="okLI" click-type="1">OK</li>
<li id="cancelLI" click-type="-1">CANCEL</li>
</ul>
<button id="ok" button-type="1">OK</button>
<button id="cancel" button-type="-1">CANCEL</button>

你不需要使用按钮,你可以将它添加到你想要点击的每个元素。

关于c# - 如何在 ASP .NET MVC 5 View 中重命名 confirm() 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41586811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com