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:

  • Is it safe to use something similar to the snippet above?
  • Is there some canonical list of strings that should generally NOT be used as input names?

  • 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.

    链接地址: http://www.djcxy.com/p/13158.html

    上一篇: 在语音通话期间录制(wav)文件?

    下一篇: 输入不应该使用的名称?