<script type="text/javascript">
function run()
{
var paper = Raphael( $('.wrapper')[0], 600, 600 ),
path = paper.path( Raphael.transformPath(pdefs[useDef].path, pdefs[useDef].transform) )
.attr( 'stroke-width', 10 )
.attr( 'stroke', 'rgb(80,80,80)' ),
$shim = $('<div id=\'shim-1\'><img src=images/buttons/photo.png></div>') //How to use php assign this line?
}
$(function() {
run();
});
</script>
我想用php编写一行代码:$shim = $('<div id=\'shim-1\'><img src=images/buttons/photo.png width=75px height=75px></div>')
。我可以写下面的代码吗? :
<script type="text/javascript">
function run()
{
var paper = Raphael( $('.wrapper')[0], 600, 600 ),
path = paper.path( Raphael.transformPath(pdefs[useDef].path, pdefs[useDef].transform) )
.attr( 'stroke-width', 10 )
.attr( 'stroke', 'rgb(80,80,80)' ),
</script>
<?php
Use mysql get data from database...
if (condition) {
?>
<script type="text/javascript"> $shim = $('<div id=\'shim-1\'><img src=images/buttons/photo.png width=75px height=75px></div>') </script>
<?php
}
?>
<script type="text/javascript">
}
$(function() {
run();
});
</script>
但我认为该页面将首先加载php,这意味着将首先分配$shim
,然后才开始执行javascript function run()
。因此,$shim
将在javascript function run()
之外,如何使用php将$shim
分配到javascript function run()
?
我发现了实际上是什么。实际上我在启动php标记</script>
之前关闭了javascript标记<?php
。实际上我可以直接启动php标签而无需关闭javascript标签。例如,<script type="text/javascript"> Java codes here... <?php php codes here.... ?>
<script type="text/javascript">
function run()
{
var paper = Raphael( $('.wrapper')[0], 600, 600 ),
path = paper.path( Raphael.transformPath(pdefs[useDef].path, pdefs[useDef].transform) )
.attr( 'stroke-width', 10 )
.attr( 'stroke', 'rgb(80,80,80)' ),
<?php
Use mysql get data from database...
if (condition) {
$shim = $('<div id=\'shim-1\'><img src=images/buttons/photo.png width=75px height=75px></div>')
<?php
}
?>
}
$(function() {
run();
});
</script>
如何实际调用此问题?我认为这个问题不是关于javascript之前的php加载......
答案 0 :(得分:1)
请考虑大致发生的事情:
因此,在服务器上执行PHP之后,会在客户端上执行JavaScript。
现在问到你的详细问题,对我来说似乎只是想要
function run() {
var paper = Raphael( $('.wrapper')[0], 600, 600 ),
path = paper.path(
Raphael.transformPath(pdefs[useDef].path,
pdefs[useDef].transform))
.attr( 'stroke-width', 10 )
.attr( 'stroke', 'rgb(80,80,80)' );
// string broken into three strings to avoid scrolling
$shim = $('<div id=\'shim-1\'>' +
'<img src=images/buttons/photo.png ' +
'width=75px height=75px></div>');
}