How to keep some input text removed by jquery when going back with browser?

前端 未结 4 1519
滥情空心
滥情空心 2021-01-20 10:44

I have some bug with the following page: http://jsbin.com/agedu/ Source code with some comments: http://jsbin.com/agedu/edit

The problem is that when typing somethin

4条回答
  •  借酒劲吻你
    2021-01-20 11:21

    When you initialize your plugin, you were setting resetting the value of the inputs, I just refactored a bit and added the following check:

            if (this.value === '' || this.value === hvalue){
              $(this).attr('value', hvalue).addClass(opts.hclass);
            }
    

    I separated that operations from your focus event connection chain.

    Now it will only set the default value (hvalue) and the default gray class (hclass) if the element value is '' or it has the default value.

    Check your snippet here.

提交回复
热议问题