我在我的购物车中开发了一个缩放工具,我仍然坚持如何在jQuery函数中调用PHP变量.
这是我的代码:
jQuery(document).ready(function($){
$('#image1').addimagezoom({ // single image zoom
zoomrange: [3, 10],
magnifiersize: [800,300],
magnifierpos: 'right',
cursorshade: true,
largeimage: "php variable" //we add the directory of the image.
});
});
我需要把
$src ="images/products/".mysql_result($execute_select_product_query,0,'image1')."
在我的函数中,我把PHP变量.
解决方法:
你有两三个选择:如果Javascript在php文件中,你可以
var phpVar = <?php echo $var; ?>;
否则,如果Javascript在任何地方,你可以这样做:
然后将其作为
$('#phpVar').val();
例1:
jQuery(document).ready(function($){
$('#image1').addimagezoom({ // single image zoom
zoomrange: [3, 10],
magnifiersize: [800,300],
magnifierpos: 'right',
cursorshade: true,
largeimage: <?php echo $var; ?> //we add the directory of the image.
});
});
例2:
HTML:
使用Javascript
jQuery(document).ready(function($){
$('#image1').addimagezoom({ // single image zoom
zoomrange: [3, 10],
magnifiersize: [800,300],
magnifierpos: 'right',
cursorshade: true,
largeimage: $('#phpVar').val(); //we add the directory of the image.
});
});
标签:jquery,php,javascript
来源: https://codeday.me/bug/20190711/1435298.html