如何在 javascript 弹出框中显示消息

How to display a message in javascript pop up boxes

在 y 项目中,我使用这个库来显示弹出框 http://fabien-d.github.io/alertify.js/

准确地说,我正在使用警报指令来显示弹出消息。我的问题是,有没有一种方法可以将 html 文本传递到 java 脚本函数中以显示消息?

例如

在我的文件中我有类似的东西:

> <p>  I want this to be displayed as a message in the alertify pop up
> message box </p>

显示消息

<script> 
    function message() {
        alertify.alert(/**this is where i would like to pass the message from  html 
        to be displayed but how would i do this?**/); 
    }
</script>

对于 Alertify 消息,我使用这个:

window.showAlert = function(){
    alertify.alert('<a href="javascript:showConfirm();">Show Confirm</a>');
}

window.showConfirm = function(){
    alertify.confirm('<a href="javascript:showAlert();">Show Alert</a>');
}
//works with modeless too
alertify.alert().setting('modal', false);
alertify.confirm().setting('modal', false);

window.showAlert();

你可以看看here

添加一些 id 到文本容器:

 <p id='text1'>  I want this to be displayed as a message in the alertify pop up message box </p>

然后:

function message( text ) { alertify.alert( text ); }

message( $('#text1').text() );

你需要将 id 设置为 <p>: <p id='text'> I want this to be displayed as a message in the alertify pop up message box </p>

并使用 javascript 获取它: alertify.alert(document.getElementById("text").innerHTML)