access form input field by Name

This question already has an answer here:

  • How can I select an element by name with jQuery? 15 answers

  • 要做到这一点正确的选择是

    $('input[name=fname]')
    

    查看您可以使用的所有选择器:https://api.jquery.com/category/selectors/

    $('input[name=fname]').on('blur', function() {
     //your code ...
    });
    

    You can do

    $('[name="fname"]')
    

    But it is recommended to use an id/class that is more efficient that doing an attribute selector.

    http://learn.jquery.com/using-jquery-core/selecting-elements/ http://learn.jquery.com/performance/optimize-selectors/

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

    上一篇: 这个功能可以使用名称而不是ID来完成吗?

    下一篇: 按名称访问表单输入字段