javascript确认框中的html?

javascript确认框中的html?,javascript,html,Javascript,Html,是否可以在JavaScript确认框中插入HTML代码 我刚刚尝试过&它似乎不起作用(我尝试添加一个HTML链接),请参见下面的代码 <html> <head> <script type="text/javascript"> function show_alert() { confirm(<a href="www.url.com">Link text</a>); } </script> </he

是否可以在JavaScript确认框中插入HTML代码

我刚刚尝试过&它似乎不起作用(我尝试添加一个HTML链接),请参见下面的代码

<html> 
  <head> 
     <script type="text/javascript"> function show_alert() { confirm(<a href="www.url.com">Link text</a>); } </script> 
  </head>
  <body>
    <input type="button" onclick="show_alert()" value="Show alert box" />
  </body>
</html>

函数show_alert(){confirm();}

我怀疑我可能必须使用这样的库才能使其工作

不可能在
js
确认框中包含
HTML

您认为必须使用对话框
jquery
插件是对的


要获得类似于确认/警报框的效果,您必须创建模式对话框。

不,警报功能无法实现


但是,如果您想要使用html代码确认框,可以在屏幕上添加一个带有绝对位置的框,该框可以包含您想要的任何html。

您只能在alert()、confirm()和prompt()中插入纯文本框。

HTML将不会被解析并显示在
确认
框中。

如果您可以使用Jquery,请尝试下面的代码,这可以使代码根据您的要求工作

javascript中的函数定义:

<script>
        function ConfirmMessage(title, message) {
            $('#confirmboxpopup').fadeIn(500, function () {
                $('#confirmbox').animate({ 'top': '100px' }, 50);
            });
            $('#confirmboxtitle').html(title);
            $('#confirmboxmessage').html(message);
            $('#confirmbox').show(50);
            $('#confirmboxok').attr('onclick', okFunction());
            $('#confirmboxcancel').attr('onclick', onCancelClickFunction());
        }

        function okFunction()
        {
           'enter code here to implement next step if user agree'
        }

        function onCancelClickFunction()
        {
           'enter code here to fadeout for id #confirmboxpopup to remove popup.'
        }
</script>

功能确认消息(标题、消息){
$('#confirmboxpopup').fadeIn(500,函数(){
$('confirbox').animate({'top':'100px',50);
});
$('#confirmboxtitle').html(title);
$('#confirmboxmessage').html(message);
$(#confirbox')。show(50);
$('confirmboxok').attr('onclick',okFunction());
$('confirmboxcancel').attr('onclick',onCancelClickFunction());
}
函数okFunction()
{
'如果用户同意,在此处输入代码以执行下一步'
}
函数onCancelClickFunction()
{
'在此处输入代码以淡出id#confirmboxpopup以删除弹出窗口。'
}
使用id在HTML中定义标记:

<div id="confirmboxpopup" class="confirmboxpopup" style="display: none"></div>
<div id="confirmbox" class="confirm_message">
        <div id="confirmboxtitle" class="title"></div>
        <div id="confirmboxmessage" class="message"></div>
        <div id="confirmbuttons" style="float: right; padding-top: 7px">
            <button id="confirmboxok" type="button">ok</button>
            <button id="confirmboxcancel" type="button">cancel</button>
        </div>
    </div>

好啊
取消
调用函数:
您只需要使用“ConfirmMessage(title,message)”之类的参数调用ConfirmMessage。

我只需要使用jQuery UI对话框或其他选项。远离内置的确认/警报框。这样可以获得更多功能。这不是同步程序流,您的
ConfirmMessage
无法根据用户选择返回
true
false