代码区项目交易流程

Find the element type of a form after finding it by name or by identifier


Probably a dumb question, but is there a way in javascript to find out a form element's type (text, checkbox, etc.) from a form element after finding it by name or id? Either in plain old JavaScript or using jQuery-style syntax or methods would be ideal.

Example:

<input type="text" name="my_text_input" id="my_text_input"/> <script>var element = document.getElementById('my_text_input'); // now how to get the element type?</script>

I'm not looking for alternatives, this is exactly what I want to do. I'm making a sort of screen scraper that needs to collect this information.

The type property will give you this...

document.getElementById('my_text_input').type;

However, you have also tagged the question with jQuery, so you could use...

$('#my_text_input').attr('type');

jsFiddle .

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

点击收藏

LAST Artificial Intelligence in JavaScript with TensorFlow.js After pasting the way to go to the other end of the inserted text NEXT