Input names that should not be used?
Earlier, I was creating a form and mindlessly named one of my inputs "name", similar to the following pseudo code:
<input id="name" type="text" name="name" />
I then remembered that in the past, I've had issues with inputs with the name "action." If I remember correctly, the issues arose during enhancement with JavaScript (there was confusion between the form's action and the input with the name "action").
So my questions are:
There's mostly problems if you're using shortcuts like myform.action
as action
is a property of the form
element (like are id
, parentNode
, and some other properties you can see using console.dir(myform)
).
You should always use the fast and reliable way :
var inputElement = document.getElementById('action');
or, using jQuery :
var $input = $('#action');
As noticed by epascarello, you'll also have problem if you call or use a property that you overrided by defining an element with that name, for example submit
. But as you're the one calling it in your code, it should be obvious if it happens.
上一篇: 在语音通话期间录制(wav)文件?
下一篇: 输入不应该使用的名称?