回声 php javascript 警报?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19780988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
echo php javascript alert?
提问by Anaes Arias
How can I echo this javascript if the php error messages is called? I have an error message setting that when a user misses his username or password it triggers an error message. The php error message is called by a php code. Here is the code:
如果调用了 php 错误消息,我该如何回显这个 javascript?我有一个错误消息设置,当用户错过他的用户名或密码时,它会触发一条错误消息。php 错误信息是由 php 代码调用的。这是代码:
<?php echo showmessage($msg) ?>
I have an alert message in javascript that when called it will make a javascript css pop up alert box. IF the javascript code is present it will show the alert box right away after reload. Here is code:
我在 javascript 中有一条警报消息,当它被调用时,它会弹出一个 javascript css 警报框。如果存在 javascript 代码,它将在重新加载后立即显示警报框。这是代码:
<script type="text/javascript">
$(document).ready(function () {
jqxAlert.alert('Alert Message');
})
</script>
How can I incorporate so that when the php echo message comes up it will trigger the javscript alert message. I was trying an if in php, so something like this code:
我如何合并,以便当 php 回显消息出现时,它将触发 javscript 警报消息。我在 php 中尝试了一个 if,所以像这样的代码:
if ( showmessage($msg) ) {
<script type="text/javascript">
$(document).ready(function () {
jqxAlert.alert('Alert Message');
})
</script>
}
How can I echo my javascript message on the php call?
如何在 php 调用中回显我的 javascript 消息?
采纳答案by aretecode
This could be written like this:
这可以写成这样:
<?php if (showmessage($msg)): ?>
<script>
$(document).ready(function (){
jqxAlert.alert('Alert Message');
});
</script>
<?php endif; ?>
Or like this:
或者像这样:
<?php if (showmessage($msg)) { ?>
<script>
$(document).ready(function (){
jqxAlert.alert('Alert Message');
});
</script>
<?php } ?>
Or like this:
或者像这样:
<?php
if (showmessage($msg)) {
echo
'
<script>
$(document).ready(function (){
jqxAlert.alert(\'Alert Message\');
});
</script>
';
}
?>
short hand comparison (ternary)
Or even this (probably not the best idea though):
甚至这个(虽然可能不是最好的主意):
<?= (showmessage($msg)) ? '<script>$(document).ready(function (){jqxAlert.alert(\'Alert Message\');});</script>' : ""; ?>
Alternatively, if you mean you would like to put the error message inthat alertbox
或者,如果您的意思是要将错误消息放在该警报框中
<?php
if (showmessage($msg)) {
echo
'
<script>
$(document).ready(function (){
jqxAlert.alert('.showmessage($msg).');
});
</script>
';
}
?>
and again in the first style:
再次以第一种方式:
<?php if (showmessage($msg)): ?>
<script>
$(document).ready(function (){
jqxAlert.alert(<?= showmessage($msg) ?>);
});
</script>
<?php endif; ?>
回答by Ronak Patel
something like this.. close your php tag before starting to write javascript..
像这样的东西.. 在开始编写 javascript 之前关闭你的 php 标签..
<?php if ( showmessage($msg) ) { ?>
<script type="text/javascript">
alert('Alert Message');
</script>
<?php } ?>
回答by Krish R
Can you try this
你能试试这个吗
<?PHP if ( showmessage($msg) ) { ?>
<script type="text/javascript">
$(document).ready(function () {
jqxAlert.alert('Alert Message');
});
</script>
<?PHP } ?>