简体   繁体   English

无法在php中调用函数onfocus事件

[英]Not able to call a function onfocus event in php

I am not able to call a functions on onfocus and onblur events, both perfectly working in html but not in php here is code in php: 我无法在onfocus和onblur事件上调用函数,两者都可以完美地在html中工作,但不能在php中工作,这里是php中的代码:

echo "<input value='Enter Name' onfocus= 'areaOnFocus(text1, 'Enter Name')' onblur='areaOnBlur(text1, 'Enter Name')' type='text' name='text1' id='text1'>";

both functions are called in script tag. 这两个函数都在脚本标签中调用。 I am sure that call to function is not made in this case as I am alerting in script tag , but nothing happen. 我确定在这种情况下不会调用函数,因为我在script标签中发出警报,但是什么也没有发生。

thank you in advance. 先感谢您。

Well you're messing up with quotes there. 好吧,你搞砸了那里的报价。 I think you're using single quotes everywhere to avoid problems with the double quotes enclosing the string, but then you have this problem: 我认为您到处都在使用单引号来避免将字符串括在双引号中的问题,但是然后您遇到了这个问题:

onfocus= 'areaOnFocus(text1, 'Enter Name')'

the single quote starts the string at areaOnFocus and ends it before Enter name . 单引号将字符串从areaOnFocus开始,并 Enter name 之前结束。

You can either play with double quotes spamming like this: 您可以使用双引号发送垃圾邮件,如下所示:

echo "<input value=\"Enter Name\" onfocus=\"areaOnFocus(text1, 'Enter Name')\" onblur=\"areaOnBlur(text1, 'Enter Name')\" type=\"text\" name=\"text1\" id=\"text1\">";

or - better - put the HTML code outside PHP blocks. 或者-更好-将HTML代码放在 PHP块之外

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM