在项目中,我使用此库来显示弹出框http://fabien-d.github.io/alertify.js/
准确地说,我使用alert指令来显示弹出消息。我的问题是,有没有办法可以将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>
答案 0 :(得分:0)
对于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
答案 1 :(得分:0)
在文本容器中添加一些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() );
答案 2 :(得分:0)
您需要将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)