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
Post a Comment