我想在javascript中显示确认对话框中的消息,而不使用html或任何其他

I want to display a message in confirm dialog in javascript without using html or any other

本文关键字:html 任何 其他 消息 javascript 显示 确认 对话框      更新时间:2023-09-26

我想在确认对话框中显示"是否要删除?"

我在数据内容中给出了该消息,但它不起作用。

我怎么能做到这一点,只使用javascript

下面是我的代码:
function confirmDelete ( a )
{   
$(function() {
    $( "#dialog-confirm" ).dialog({
      data : "Do you want to delete?",
      resizable: false,
      height:140,
      modal: true,
      buttons: {
        "YES": function() {
            $(this).load("./removeAgent.action?id="+a,  function() {
                $("#agentResult").trigger("reloadGrid");
            });
            $(this).dialog("close");
        },
        "   NO    ": function() {
            $(this).dialog("close");
        }
      }
    });
});

}

你可以在javascript中使用confirm方法。

html部分

点击按钮,显示确认框。

<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

JavaScript部分

<script>
    function myFunction(){
    var x;
    var r=confirm("Press a button!");
    if (r==true){
      x="You pressed OK!";
      }
    else{
      x="You pressed Cancel!";
      }
    document.getElementById("demo").innerHTML=x;
    }
</script>

如果你想使用jquery插件,看看下面的链接。

http://jquery-plugins.net/tag/confirm-box

http://fabien-d.github.io/alertify.js/0.4.0rc1/

在onClick侦听器中尝试此方法,

    <script>
        function clickAction()
{
        var result;
        var buttonpressed=confirm("Button Press");
        if (buttonpressed==true)
{
          result="OK";
          }
        else
{
          result="Cancel";
          }
        document.getElementById("demo").innerHTML=result;
        }
    </script>
相关文章: