Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 这将在jQuery中转换为对象_Javascript_Jquery_Html - Fatal编程技术网

Javascript 这将在jQuery中转换为对象

Javascript 这将在jQuery中转换为对象,javascript,jquery,html,Javascript,Jquery,Html,我试图编写一个小函数,从html中获取一个div元素,隐藏它,分配一个值和一个变量名,然后将其解析到函数中,检查分配的月份(值)是否等于当前月份。我认为它不起作用的原因是“this”正在被转换成一个对象,并且它没有存储我正在解析的变量的值 var currentMonth = (new Date).getMonth() + 1; var valentinesdiv = $('#valentinesmenu'); $(valentinesdiv).hide(); valentinesdiv = 5

我试图编写一个小函数,从html中获取一个div元素,隐藏它,分配一个值和一个变量名,然后将其解析到函数中,检查分配的月份(值)是否等于当前月份。我认为它不起作用的原因是“this”正在被转换成一个对象,并且它没有存储我正在解析的变量的值

var currentMonth = (new Date).getMonth() + 1;
var valentinesdiv = $('#valentinesmenu');
$(valentinesdiv).hide();
valentinesdiv = 5;
$.fn.datechecker1 = function () {
    if ($(this) == currentMonth) {
        this.show();
    } else {
        alert(this);
    }
};
$(valentinesdiv).datechecker1();

它直接进入警报框并输出object object,这样在我解析它时它就不会保存变量的值。

我看到的几个问题是,您试图在纯JS
this
对象上使用jQuery
show()
实际上是传入对象,而不是对象内部的某个值

您最可能想要的是:

var element = $(this), value = element.val();
if(value == currentMonth){
  element.show();
} else {
  alert(value);
}

我看到的几个问题是,您试图在纯JS
this
对象上使用jQuery
show()
,并且您在警报框中看到了
object对象,因为
alert(this)
实际上是传入对象,而不是对象中的某个值

您最可能想要的是:

var element = $(this), value = element.val();
if(value == currentMonth){
  element.show();
} else {
  alert(value);
}

我看到的几个问题是,您试图在纯JS
this
对象上使用jQuery
show()
,并且您在警报框中看到了
object对象,因为
alert(this)
实际上是传入对象,而不是对象中的某个值

您最可能想要的是:

var element = $(this), value = element.val();
if(value == currentMonth){
  element.show();
} else {
  alert(value);
}

我看到的几个问题是,您试图在纯JS
this
对象上使用jQuery
show()
,并且您在警报框中看到了
object对象,因为
alert(this)
实际上是传入对象,而不是对象中的某个值

您最可能想要的是:

var element = $(this), value = element.val();
if(value == currentMonth){
  element.show();
} else {
  alert(value);
}

下面的
js
假设实现是在特定的
元素处设置变量
x
5
#valentinesmenu
;然后检查变量是否等于变量
currentMonth

x
5
设置为
#valentinesmenu
text
$.fn.datechecker1
检查是否调用了元素,并且该元素的
文本
是否等于
当前月
; 如果为true,则调用
元素上的
.show()
,如果为true,则将
此.text()、currentMonth、x
记录到
控制台

不确定这是否是预期结果或要求;下面的
js
基于上述假设


尝试使用
.text()

var currentMonth=(新日期).getMonth()+1;
变量x=5;/?
var valentinesdiv=$(“#valentinesmenu”);
//将'valentinesdiv'的文本设置为'currentMonth'`
valentinesdiv.text(x.hide();
$.fn.datechecker1=函数(){
//如果`this.text()==currentmount`do stuff
if(this.text()==currentMonth){
this.show();
}否则{
//否则,做其他事情
console.log(this.text(),currentMonth,x);
}
};
valentinesdiv.datechecker1()


js
下面假设实现是在特定的
元素处设置变量
x
5
#valentinesmenu
;然后检查变量是否等于变量
currentMonth

x
5
设置为
#valentinesmenu
text
$.fn.datechecker1
检查是否调用了元素,并且该元素的
文本
是否等于
当前月
; 如果为true,则调用
元素上的
.show()
,如果为true,则将
此.text()、currentMonth、x
记录到
控制台

不确定这是否是预期结果或要求;下面的
js
基于上述假设


尝试使用
.text()

var currentMonth=(新日期).getMonth()+1;
变量x=5;/?
var valentinesdiv=$(“#valentinesmenu”);
//将'valentinesdiv'的文本设置为'currentMonth'`
valentinesdiv.text(x.hide();
$.fn.datechecker1=函数(){
//如果`this.text()==currentmount`do stuff
if(this.text()==currentMonth){
this.show();
}否则{
//否则,做其他事情
console.log(this.text(),currentMonth,x);
}
};
valentinesdiv.datechecker1()


js
下面假设实现是在特定的
元素处设置变量
x
5
#valentinesmenu
;然后检查变量是否等于变量
currentMonth

x
5
设置为
#valentinesmenu
text
$.fn.datechecker1
检查是否调用了元素,并且该元素的
文本
是否等于
当前月
; 如果为true,则调用
元素上的
.show()
,如果为true,则将
此.text()、currentMonth、x
记录到
控制台

不确定这是否是预期结果或要求;下面的
js
基于上述假设


尝试使用
.text()

var currentMonth=(新日期).getMonth()+1;
变量x=5;/?
var valentinesdiv=$(“#valentinesmenu”);
//将'valentinesdiv'的文本设置为'currentMonth'`
valentinesdiv.text(x.hide();
$.fn.datechecker1=函数(){
//如果`this.text()==currentmount`do stuff
if(this.text()==currentMonth){
this.show();
}否则{
//否则,做其他事情
console.log(this.text(),currentMonth,x);
}
};
valentinesdiv.datechecker1()


js
下面假设实现是在特定的
元素处设置变量
x
5
#valentinesmenu
;然后检查变量是否等于varia