我有以下javascript
function showIt(item,i,j,max){
var id;
actualItem=item;
for(var x=1;x<=i;x++){
id=item+"_"+x;
document.getElementById(id).src="<?= suburl(); ?>/b.gif";
}
for(var x=i+1;x<=max;x++){
id=item+"_"+x;
if(x<=j)
document.getElementById(id).src="<?= suburl(); ?>/y.gif";
else document.getElementById(id).src="<?= suburl(); ?>/w.gif";
}
}
我尝试过<?= suburl(); ?>
和<?php echo suburl(); ?>
函数suburl();看起来像这样:
function suburl() {
$suburl = 'http://localhost/www.site.com/static';
echo $suburl;
}
它并没有在javascript中回应它。它看起来像纯HTML。 非常感谢谢谢。
答案 0 :(得分:1)
你可以尝试这样的事情:
function showIt(item,i,j,max){
var id;
actualItem=item;
var url = suburl(); //THIS IS NEW
for(var x=1;x<=i;x++){
id=item+"_"+x;
document.getElementById(id).src=url+"/b.gif";
}
for(var x=i+1;x<=max;x++){
id=item+"_"+x;
if(x<=j)
document.getElementById(id).src=url+"/y.gif";
else document.getElementById(id).src=url+"/w.gif";
}
}
function suburl() {
var suburl = 'http://localhost/www.site.com/static';
return suburl;
}
答案 1 :(得分:-5)
function showIt(item,i,j,max){
var id;
actualItem=item;
for(var x=1;x<=i;x++){
id=item+"_"+x;
document.getElementById(id).src="<?= echo suburl(); ?>/b.gif";
}
for(var x=i+1;x<=max;x++){
id=item+"_"+x;
if(x<=j)
document.getElementById(id).src="<?= echo suburl(); ?>/y.gif";
else document.getElementById(id).src="<?= echo suburl(); ?>/w.gif";
}
}
函数suburl();看起来像这样:
function suburl() {
$suburl = 'http://localhost/www.site.com/static';
return $suburl;
}
希望这个帮助。 感谢