我在php和jQuery / Javascript之间有问题......它不会出现或无法正常工作。
我的代码:
if($bottom_1_banner == "true"){
//$data_AD .= '$(\'.ban_bottom\').html(\''.htmlentities($bottom_banner).'\').text();';
$data_AD .= '$(\'.ban_bottom\').html("'.htmlspecialchars($bottom_banner).'").text();';
}
错误日志:( Chrome / Safari)
<script type="text/javascript">
$(document).ready(function() {
$('.ban_bottom').html("<!-- xxxxxxx -->
******index.php:11 Uncaught SyntaxError: Unexpected token ILLEGAL******
<script type="text/javascript">
xxxxxxx_bid = "xxxxxxxxxxx";
</script>
<script type="text/javascript" src="http://xxx.xxxxxx.com/k.js"></script>
<!-- xxxxxxxx -->").text(); });
</script>
OR
编辑:将图像转换为文本。
答案 0 :(得分:1)
我在JavaScript中的新行遇到了同样的问题。如果您从MySql获取值,可以尝试:
$php_string = str_replace('<br />','<br />\\',nl2br($php_string));
首先使用html <br/>
标记替换换行符,然后在生成的<br/>
标记后添加\;所以JS行总是以\结尾,表示JavaScript代码中的正确的新行。
答案 1 :(得分:0)
根据您的上述代码,有一件事是肯定的,您需要在使用$data_AD
之前定义.=
变量,或者在没有=
的情况下使用.
答案 2 :(得分:0)
也许做
$data_AD .= '$(\'.ban_bottom\').html("'.$bottom_banner.'").text();';
...
<?php echo str_replace('\n', '\\n', $data_AD); ?>
删除换行符?
答案 3 :(得分:0)
摆脱HTML中的新行。 Javascript不理解多行的字符串。您也可以用\ \ n:
替换\ n这不起作用:
var a = "This is a
string for me";
这有效
var a = "This is a \
string for me";
或
var a = "This is a string for me";
答案 4 :(得分:0)
这行代码在这里完美无瑕。 我猜它是.php文件的文件编码问题。检查不良字符。