问个比较基础的关于jQuery问题

 $("#loginSubmit").click(
    alert()
  );
 $("#loginSubmit").click(function(){
    alert()
  });

这两种学法,第一种学法的错误

$("#loginSubmit").click();要求的是填入一个自定义函数,给jquery.js调用,
alert()是使用一个函数,也就是js语句了。所以错误

第一种只能执行一个语句alert(),而第二种是执行一个function,一个function可以有很多语句。

因为这里需要的是一个函数,不能是一个语句

click内的参数其实是一个function,因此应该填入一个函数名或者直接写一个匿名函数,即function(){ xxx }

click是一个点击事件函数,要用function,里面可以是语句,也可以是函数如alert函数

看清楚cick的定义就好

click是一个点击事件函数,函数体可以是语句,也可以是具体函数

 special: {
        load: {

            // Prevent triggered image.load events from bubbling to window.load
            noBubble: true
        },
        focus: {

            // Fire native event if possible so blur/focus sequence is correct
            trigger: function() {
                if ( this !== safeActiveElement() && this.focus ) {
                    this.focus();
                    return false;
                }
            },
            delegateType: "focusin"
        },
        blur: {
            trigger: function() {
                if ( this === safeActiveElement() && this.blur ) {
                    this.blur();
                    return false;
                }
            },
            delegateType: "focusout"
        },
        click: {

            // For checkbox, fire native event so checked state will be right
            trigger: function() {
                if ( this.type === "checkbox" && this.click && nodeName( this, "input" ) ) {
                    this.click();
                    return false;
                }
            },

            // For cross-browser consistency, don't fire native .click() on links
            _default: function( event ) {
                return nodeName( event.target, "a" );
            }
        },

        beforeunload: {
            postDispatch: function( event ) {

                // Support: Firefox 20+
                // Firefox doesn't alert if the returnValue field is not set.
                if ( event.result !== undefined && event.originalEvent ) {
                    event.originalEvent.returnValue = event.result;
                }
            }
        }
    }
};