简体   繁体   English

在javascript确认框中的HTML?

[英]html in javascript confirm box?

Is it possible to insert HTML code in a JavaScript confirm box? 是否可以在JavaScript确认框中插入HTML代码?

I just tried & it does not seem to work (I try to add a HTML link), see my code below 我刚尝试过它似乎没有用(我尝试添加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>

I suspect I might have to use a library such as "jquery-ui's dialog" to get this working 我怀疑我可能不得不使用诸如“jquery-ui的对话框”之类的库来实现这一点

您只能将明文插入alert(),confirm()和prompt()框。

No, it isn't possible with the alert function. 不,警报功能无法实现。

However, if you want confirm boxes with html code, you could add a <div> with an absolute position on the screen, which can contain any html you want. 但是,如果您想要使用html代码确认框,则可以在屏幕上添加一个具有绝对位置的<div>,其中可以包含您想要的任何html。

It is not possible to include HTML in js confirm boxes. 无法在js确认框中包含HTML

You are right in thinking you will have to use a dialog jquery plugin. 你是对的,你认为你将不得不使用对话框jquery插件。

To get an effect similar to confirm/alert boxes, you will have to create Modal dialog boxes. 要获得类似于确认/警告框的效果,您必须创建模态对话框。

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

If you can use Jquery please try below code, this can give you possibility to make code work according to your requirement. 如果您可以使用Jquery,请尝试下面的代码,这可以让您根据您的要求使代码工作。

function definition in javascript: 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>

Define tags in HTML with id: 使用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>

Calling function: you only need to call ConfirmMessage with parameters like "ConfirmMessage(title, message)". 调用函数:您只需要使用“ConfirmMessage(title,message)”等参数调用ConfirmMessage。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM