我正在编写我的第一个 jQuery 并获得一个Uncaught TypeError: object is not a function
. 最初设置水印的代码的第一部分很好。但是,当我尝试访问输入字段时,blur
和focus
函数都会引发错误。.val()
有谁知道原因吗?
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');
}
})
});