1. 程式人生 > >jQuery—$ is not a function

jQuery—$ is not a function

        昨天編寫程式碼,在使用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();”