Javascript jQuery水印抛出类型错误:对象不是函数

Javascript jQuery水印抛出类型错误:对象不是函数,javascript,jquery,Javascript,Jquery,我正在编写我的第一个jQuery,并得到一个未捕获的TypeError:object不是一个函数。最初设置水印的代码的第一部分很好。但是,当我尝试访问输入字段的.val()时,blur和focus函数都会引发错误。有人知道原因吗 jQ(document).ready(function($) { var $watermark = 'dd-MMM-yyyy'; var $calendarVal = $('#tabForm\\:opStartInputDate').val(); /* this wor

我正在编写我的第一个jQuery,并得到一个
未捕获的TypeError:object不是一个函数
。最初设置水印的代码的第一部分很好。但是,当我尝试访问输入字段的
.val()
时,
blur
focus
函数都会引发错误。有人知道原因吗

jQ(document).ready(function($) {
var $watermark = 'dd-MMM-yyyy';
var $calendarVal = $('#tabForm\\:opStartInputDate').val(); /* this works no problem */
if ($calendarVal == null || $calendarVal == '')
{
    alert('Inside null or empty conditional');
    $('#tabForm\\:opStartInputDate').val($watermark).addClass('watermark');  /* this works no problem */
}
$('#tabForm\\:opStartInputDate').blur(function($){
    var blurCalendarVal = $('#tabForm\\:opStartInputDate').val();  /* this line throws the error */
    if (blurCalendarVal == null || blurCalendarVal == '' || blurCalendarVal.length == 0)
    {
        alert('Inside blur function conditional');  /* Never make it here */
        $('#tabForm\\:opStartInputDate').val(watermark).addClass('watermark');
    }
})
$('#tabForm\\:opStartInputDate').focus(function($){
    /*if ($(this).val() == watermark) This is commented out but this throws the error as well
    {
        $(this).val('').removeClass('watermark');
    }*/
    var $focusCalendarVal = $('#tabForm\\:opStartInputDate').val(); /* this line throws the error */
    var $watermarkDate = 'dd/MMM/yyyy';
    if ($focusCalendarVal == $watermarkDate)
    {
        alert('Inside focus function conditional');
        $('#tabForm\\:opStartInputDate').val('').removeClass('watermark');
    }
})
}))

这一行:

$('#tabForm\\:opStartInputDate').blur(function($){
您正在将
$
重新映射为传递给处理程序的
事件
对象。使用不同的参数名称,如
e
event

$('#tabForm\\:opStartInputDate').blur(function(e){ // fixed

我猜你的困惑源于开场白

jQ(document).ready(function($) {

jQuery().ready()
处理程序将
jQuery
作为其第一个参数接收,因此在此处使用
$
可确保
$
位于
ready
处理程序内部。但是,您将其错误地复制到
事件
处理程序中,该处理程序接收一个
事件
对象作为其第一个参数。在抛出错误的行中,实际上是调用
事件(…)
而不是
jQuery(…)
,因此错误
对象不是函数。

这就是问题所在!谢谢你给我解释!