<?phpfunction alert($msg) {echo "<script type='text/javascript'>alert('$msg');</script>";}if(array_key_exists('btnRegisterAdmins', $_POST)) { $fname = $_POST['FirstName'];$lname=$_POST['LastName'];if(empty($fname)){ $alertscript = "you need...<br />";}if(empty($lname)){ $alertscript = $alertscript . "<br /> to be good..."; alert($alertscript);}?>输出没有换行,并且标签本身出现。我可以用什么方法解决这个问题?
2 回答
斯蒂芬大帝
TA贡献1827条经验 获得超8个赞
alert(" hi \r\n i am at new line")
<br/>代码中第二次出现的被替换为“/r” 尝试
<?php
function alert($msg)
{
$msg = "'$msg'"; //to get message enclosed by single quotes
echo "<script type='text/javascript'>", //try other approach
"alert($msg);",
"</script>";
}
$arr = array("btnRegisterAdmins"=>1);
if(array_key_exists('btnRegisterAdmins', $arr))
{
$fname = ""; //guessing no fname
$lname=""; //guessing no lname
$alertscript ="";
if(empty($fname))
{
$alertscript = " you need...";
}
if(empty($lname))
{
$alertscript = $alertscript . '\r to be good...';
alert($alertscript);
}
}
?>
- 2 回答
- 0 关注
- 71 浏览
添加回答
举报
0/150
提交
取消