在Php中调用Js函数 [英] Call Js Function in Php

查看:73
本文介绍了在Php中调用Js函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个包含html控件的php页面。我只想定义一个js函数并将其调用为html控件的onclick事件,即img。但是,它不起作用。当我尝试在html页面中的图像点击事件中调用js函数时,它运行良好。



你能帮忙解决这个问题吗?



页面如下所示简化;



Hi,
I have a php page which includes html controls. I just want to define a js function and call it onclick event of an html control,img. But , it does not work. When I try to call js function at click event of image in html page, it works well.

Could you please help about this?

The page is like below as simplified;

<?php 

?>


<script type="text/javascript">
function testFunction(url, title, width, height){

	window.open(url,title,width,height);

}

</script>


<ul class="block_listing">
	<li>		
		<div class="block_listing_image">
			<img src="smiley.gif" alt="Smiley face" height="42" width="42"  önclick="testFunction("url","title",150,100);">
			
		</div>
        </li>
</ul> 





页面名称以mypage.html.php结束



在此先感谢您的帮助,

亲切的问候,



The page name is ended with mypage.html.php

Thanks in advance for your help,
Kind Regards,

推荐答案

至少你有一个问题:



At least one of your problems:

önclick="testFunction("url","title",150,100);"





请注意,双引号内有双引号!



首先,试试:





Notice that you have double quotes inside of double quotes!

For a start, try:

onclick="testFunction('url','title',150,100)"





旁白:

解析器会爱你吧!如上所述,为什么在不使用任何PHP时将其设为php页面?




这篇关于在Php中调用Js函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆