javascript - jQuery value pick up -


this code:

<input type="text" id="name" /> <script>     var name = $("#name").val(); </script> 

after page loaded, type in value in input box. type in chrome console after value

console.log(name); 

i empty string

use:

<input type="text" id="name" /> <script>     $(document).on('keyup', '#name', function(){         name = $(this).val();     }); </script> 

this assign value of #name variable name once value has been typed in.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -