猿问

用php在警报中换行

<?php

function 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);

}

?>

输出没有换行,并且标签本身出现。我可以用什么方法解决这个问题?


白板的微信
浏览 74回答 2
2回答

PIPIONE

<br />是html。尝试\n代替<br />标签。

斯蒂芬大帝

alert("&nbsp;hi&nbsp;\r\n&nbsp;i&nbsp;am&nbsp;at&nbsp;new&nbsp;line")<br/>代码中第二次出现的被替换为“/r” 尝试<?phpfunction alert($msg)&nbsp;{$msg = "'$msg'";&nbsp; //to get message enclosed by single quotes&nbsp;echo "<script type='text/javascript'>",&nbsp; //try other approach&nbsp; &nbsp; &nbsp;"alert($msg);",&nbsp; &nbsp; &nbsp;"</script>";}$arr = array("btnRegisterAdmins"=>1);if(array_key_exists('btnRegisterAdmins', $arr))&nbsp;{&nbsp; &nbsp; $fname = "";&nbsp; //guessing no fname&nbsp; &nbsp; $lname="";&nbsp; //guessing no lname&nbsp; &nbsp; $alertscript ="";&nbsp; &nbsp; if(empty($fname))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $alertscript = " you need...";&nbsp; &nbsp; }&nbsp; &nbsp; if(empty($lname))&nbsp; &nbsp; {&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; $alertscript = $alertscript&nbsp; . '\r to be good...';&nbsp; &nbsp; &nbsp; &nbsp; alert($alertscript);&nbsp; &nbsp; }}?>
随时随地看视频慕课网APP

相关分类

Html5
我要回答