<input id="email" name="email" type="text" value="ooooo@gmail.com">
How do I get value of id=email and print it out to my console or anywhere for testing purposes ?
I tried, but no luck :(
script type="text/javascript">
document.getElementById('email').innerText;
</script>
There are two types of elements
.innerHTML
or .html()
in jquery like div's span's etc.value
or .val()
in jquery, like input types etcall you need o do is
console.log($('#email').val()) //jquery
or
console.log(document.getElementById('email').value); // javascript
尝试
console.log($('#email').val());
这会将整个对象“打印”到控制台
console.log("input[id='email'] - %o", document.getElementById('email'));
没有 jQuery:
console.log(document.getElementById('email').value);
有用
console.log(email.value)
在 Chrome 开发工具控制台中删除 .value:
document.getElementById('#id')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.