$(this)在javascript中的含义是什么
我有以下代码的日历弹出,这是工作良好$(this)在javascript中的含义是什么,javascript,jquery,calendar,Javascript,Jquery,Calendar,我有以下代码的日历弹出,这是工作良好 <input type="text" value="12/01/2010" readonly="readonly" name="start_date_1" id="start_date_1" disabled="disabled"/> <img src="/images/calendar_date_select/calendar.gif" onclick="new CalendarDateSelect( $(this).previou
<input type="text" value="12/01/2010" readonly="readonly" name="start_date_1" id="start_date_1" disabled="disabled"/>
<img src="/images/calendar_date_select/calendar.gif" onclick="new CalendarDateSelect( $(this).previous(), {popup:'force', year_range:10} );" class="calender_image" alt="Calendar"/>
当然JavaScript会像预期的那样失败,所以我的问题是我应该在禁用弹出()中写什么来完成它
*编辑*
我的问题可以通过将$(this)
作为参数发送来解决
function disable_pop_up(cal, id){
disable = document.getElementById(id).disabled
if (disable==true)
return false;
else
new CalendarDateSelect( cal.previous(), {popup:'force', year_range:10} );
}
onclick="disable_pop_up($(this), 'start_date_1'"
但是我的问题仍然是一样的,为什么我不能在JavaScript函数中编写类似于$(“#start_date_1”)
的东西呢?$(这)指调用函数的HTML元素。$
是jQuery
函数的缩写。只有在页面中加载了jquery库时,这才有效 在第一个示例中,$(this).previous()
将引用输入,因此如果要更改函数,请尝试
<script type="text/javascript" >
function disable_pop_up(){
if (edit==true)
new CalendarDateSelect( $("#start_date_1"), {popup:'force', year_range:10} );
else
return false;
}
</script>
功能禁用弹出窗口(){
如果(编辑==true)
新日历日期选择($(“#开始#日期#1”),{弹出窗口:'force',年份范围:10});
其他的
返回false;
}
p、 这是jQuery主函数的简写,所以我可以用上面给出的javascript函数中的其他代码替换它吗?我的javascript已经生锈了,我不明白你想实现什么。我只知道$(这个)指的是什么。抱歉,“this”不是指CalendarDateSelect的实例,在第一个代码段中它指的是img元素(您单击的那个),在第二个代码段中它指的是window元素。啊,您是对的,它指的是调用函数的HTML元素。修改以反映这一点。严格来说,javascript中的$(this)毫无意义。这是一个jquery构造。
<script type="text/javascript" >
function disable_pop_up(){
if (edit==true)
new CalendarDateSelect( $("#start_date_1"), {popup:'force', year_range:10} );
else
return false;
}
</script>