昨天编写代码,在使用jQuery获取input值时浏览器控制台显示“$ is not a function”,查看自己写的代码,发现没有写错,于是查找各种资料,终于将问题解决了:
If you are trying to add your own jQuery code to WordPress, and have had the error “$ is not a function” show up on Firebug, here is the fix:
Convert all dollar signs ($) to ‘jQuery’.The dollar sign is reserved in WordPress for the Prototype library, which is why it errors out.
其实非常简单:$已经在其他包中当做了一个变量,别忘了一个页面可以引入多个不同的JavaScript脚本库,怎么解决呢——将$换成jQuery即可,例如:把“$('userName').val();”改成“jQuery('userName').val();”