English 中文(简体)
无法将论点移至单方功能,而这种功能是变式的php文字[复制]
原标题:Unable to pass the argument to javascript function which is a variable of php script [duplicate]
  • 时间:2011-10-25 13:09:20
  •  标签:
  • php

I dont对php说新话,对如何在php和javascript之间做事有好的想法。

<!doctype html>
<html>
<head>
<Script type="text/javascript">
function show(m)
{
 var k = document.getElementById(m);
 k.src="four.jpg";
}
</head>
<body>
<? --some php code--
  $i       = 2;
  $row[$i] = "somefilename";
  printf( <img src="%s" id="%d"  onclick="show($i)"/> , $row[$i],$i);
?>

This is my sample.php file.I wanted to raise a onclick event for the image tag through javascript,The img tag is created using php script and I want it to be like these

onclick="show($i)" should be made like below
onclick="show( 2 )" <!-- and here 2 is the value of php variable

I had tried these way

 onclick="show( $i )" but it passes $i as the parameter to javascript show() function 
 but not the value 2

请帮助我这样做。 实际是可能的? 正如我知道javascript是个浏览器,而php是服务器的附带说明,我们是否能够将变数从php移至用这些方式?

最佳回答

富尼,迄今为止作出答复的每个人都改变了印刷参数,要么使用双重报价,要么压缩变量。 为什么不:

printf( <img src="%s" id="%d"  onclick="show(%d)"/> , $row[$i],$i,$i);

既然他已经使用印刷品?

此外,你实际上并不需要PHP的价值,因为它已经处于超文本状态。 你可以公正地利用:

printf( <img src="%s" id="%d"  onclick="show(this.id)"/> , $row[$i],$i);
问题回答

审判

printf( <img src="%s" id="%d"  onclick="show( .$i. )"/> , $row[$i],$i);

您引述问题

在《公共卫生法》中,单一报价中的所有内容都印成《健康年鉴》。 因此,在你看来,应当:

printf( <img src="%s" id="%d"  onclick="show(  . $i .  )"/> , $row[$i],$i);

你们需要用双字母印刷插图,以便使用一个可变的参考:

printf("<img src="%s" id="%d"  onclick="show($i)" />", $row[$i],$i);

我先对它进行了测试,但应该为你们工作。

<?php

  $i       = 2;
  $row[$i] = "somefilename";
  printf( <img src="%s" id="%d"  onclick="show(  . " " . %d . " " .  )"/> , $row[$i],$i);

?>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签