confusion over simple variable declaration jQuery “$variable” vs javascript “var”

后端 未结 5 1962
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 15:48

I have this simple ghost text implementation:

HTML code:

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 16:40

    @mgiuca is entirely right about Javascript variables - the '$' that precedes them is just a naming convention that most use to identify jQuery objects. I add this because you say

    because i tried storing jQuery object in non-jQuery variable

    but this is wrong. $txtField is a string that you are using to select an object. If you want to store the object itself you should do $txtField = $(#searchPanel form input.ghText) and then use it thusly $txtField.val().

    Having said that your code works fine for me unaltered. I've set up a demo which works on Chrome - is this a cut down version of you code?

提交回复
热议问题