Do I need to put a dollar before variable names with javascript?

前端 未结 4 1096
终归单人心
终归单人心 2021-01-11 18:19

I have the following code:

var formSubmitHandler = function (link, form) {

    //e.preventDefault();
    var $form = form;
    var val = $form.valid();
             


        
4条回答
  •  我在风中等你
    2021-01-11 18:32

    $ and jQuery are basically the jQuery instance.

    It's good to understand that $( < place something here >) is a jQuery function call and $your_variable_name is just a variable with a dollar.

    Some people use $ in their own variables to indicate that it is a jQuery object. With this naming convention, your source code would like this.

    var formSubmitHandler = function (link, form) {
        var $form = $(form);
        var val = $form.valid();
        var action = $form.data('action');
        var entity = $form.data('entity');
    

提交回复
热议问题