- Where Developers Learn, Share, & Build Careers
I have the following code, when a user selects the input box, the value will disappear, but the default value will be Once the user is re-inserted after closing it.
$ (function () {var default text = ''; $ ('input [id = input]'). Focus (function () {$ ('input' [id = input] ). $ (This). $ (This) .val (); $ (this) .val ('');}); $ ('input [id = input]'). DefaultText);})}} ; However, this is not exactly how I want it. If a user inserts the text, then I do not want to override the default text on the user that the user has inserted. I'm also quite new to jQuery so that any help would be greatly appreciated.
Your focus () method should be checked to see if Before clearing it, it is equivalent to defaultText , and in your blur () function, you have to check whether setting the defaultText First val () is empty If you are going to work with multiple inputs, it is better to use Class instead of ID, so your selector will be input.input The square will be "input" too If that was an ID, then you can call it input # input . // will run as run when the dom is ready () $ (document) .ready (function () $ ('Input.input'). ('Focus', function ( ) {// At the first focus, check to see if the default text has been saved // If not, save the current value to the data () $ (this). Data ('defaultText') $ ( This) .data ('default text', $ (this) .val ()); // Check whether the input current is equal to default $ (this) .val () == $ (this). Data (' Default text ')) $ (This) .val (' '); one one)); $ ('($ (This) .val () ==' ') $ (this) at (' blurred ', function () {// on stigma, if there is no value, set default text.) Val $ (This) .data ('defaultText'));});}); Set it to action.
Comments
Post a Comment