我正在写一个要由jquery解析的javascript字符串-它可以很好地作为警报,但不能在jquery加载函数中使用
PHP:
$imgData = 'http://www.domain.com/_image.php/_MG_4156.jpg' ;
这是一个PHP脚本,可以动态生成缩略图
<script type='text/javascript' language='javascript' charset='utf-8'>
<!--
var chart1img_".$i_gall." = new Image();
var imgData = '".$imgData."';
$(chart1img_".$i_gall.").load(function () {
$(this).hide();
$('#thumb_img_div_".$i_gall."').removeClass('loading').append(this);
$(this).fadeIn();
}).error(function () {
// notify the user that the image could not be loaded
alert(imgData);
}).attr('src', imgData);
//}).attr('src', 'http://www.domain.com/_image.php/_MG_4156.jpg');
//-->
</script>";
如果我对字符串进行硬核处理,则可以使用。
如果我将其用作imgData变量,它将失败,但警报将使用imgData起作用
尝试过弦乐连击。大败。有任何想法吗?
最佳答案
您需要在代码中添加php标签
<script type='text/javascript' language='javascript' charset='utf-8'>
<!--
var chart1img_"<?php echo $i_gall;?>" = new Image();
var imgData = '<?php echo $imgData?>';
$("chart1img_<?php echo $i_gall;?>").load(function () {
$(this).hide();
$('#thumb_img_div_<?php echo $i_gall;?>').removeClass('loading').append(this);
$(this).fadeIn();
}).error(function () {
// notify the user that the image could not be loaded
alert(imgData);
}).attr('src', imgData);
//}).attr('src', 'http://clients.flatearth.co.uk/benhopper/project/_image.php/_MG_4156.jpg');
//-->
</script>";