0
我已創建一個自定義警告對話框,但我不能將它調用PHP無法調用自定義警報的JavaScript函數在PHP
下面是警告對話框的代碼
<script>
function CustomAlert(){
this.render = function(dialog){
var winW = window.innerWidth;
var winH = window.innerHeight;
var dialogoverlay = document.getElementById('dialogoverlay');
var dialogbox = document.getElementById('dialogbox');
dialogoverlay.style.display = "block";
dialogoverlay.style.height = winH+"px";
dialogbox.style.left = (winW/2) - (550 * .5)+"px";//position of dialog box
dialogbox.style.top = "200px"; //height of the box
dialogbox.style.display = "block";
document.getElementById('dialogboxhead').innerHTML = "Registraion Succesfull";
document.getElementById('dialogboxbody').innerHTML = dialog;
document.getElementById('dialogboxfoot').innerHTML = '<button onclick="Alert.ok()">OK</button>';
}
this.ok = function(){
window.open("employer/personal","_self");
}
}var Alert = new CustomAlert();
下面
是PHP代碼
<?php
echo "<script> CustomAlert(Alert.render('You look very pretty today.')); </script>";
?>
您無法在PHP中調用JavaScript函數。在JavaScript運行時,PHP已經完成。爲了運行它,你需要捕獲一個用戶事件([見addEventListener](http://stackoverflow.com/questions/6348494/addeventlistener-vs-onclick)),例如點擊按鈕,滾動到特定位置,點擊輸入字段等。 – gibberish
您的PHP文件是否還回顯或包含定義您的CustomAlert和Alert對象的腳本塊,還是隻回顯單行?換句話說,如果在渲染後查看頁面的源代碼,它看起來像什麼? – stratedge