JQuery - Call the jquery button click event based on name property

后端 未结 4 2150
天涯浪人
天涯浪人 2021-02-13 09:46

I have one HTML button like,




        
相关标签:
4条回答
  • 2021-02-13 10:20
    $('element[name="element_name"]').click(function(){
        //do stuff
    });
    

    in your case:

    $('input[name="btnName"]').click(function(){
        //do stuff
    });
    
    0 讨论(0)
  • 2021-02-13 10:21

    You have to use the jquery attribute selector. You can read more here:

    http://api.jquery.com/attribute-equals-selector/

    In your case it should be:

    $('input[name="btnName"]')
    
    0 讨论(0)
  • 2021-02-13 10:29

    You can use the name property for that particular element. For example to set a border of 2px around an input element with name xyz, you can use;

    $(function() {
        $("input[name = 'xyz']").css("border","2px solid red");
    })
    

    DEMO

    0 讨论(0)
  • 2021-02-13 10:37

    You can use normal CSS selectors to select an element by name using jquery. Like this:

    Button Code
    <button type="button" name="mybutton">Click Me!</button>
    
    Selector & Event Bind Code
    $("button[name='mybutton']").click(function() {});
    
    0 讨论(0)
提交回复
热议问题