对象中的JQuery
为什么这会奏效对象中的JQuery,jquery,ajax,object,Jquery,Ajax,Object,为什么这会奏效 $("body").on("click",".open_popup",function(event){ event.preventDefault(); $("#form1").show(); }) 但对象内部的代码相同,如下所示: var popUpFormulario = { openWith: function () { self=this; $("body").
$("body").on("click",".open_popup",function(event){
event.preventDefault();
$("#form1").show();
})
但对象内部的代码相同,如下所示:
var popUpFormulario = {
openWith: function () {
self=this;
$("body").on("click",".open_popup",function(event){
event.preventDefault();
$("#"+self.id+"").show();
})
}
然后像这样调用函数
popUpFormulario.openWith()
只是不会?我不明白。有人能给我解释一下吗?提前感谢您的问题似乎是这一行:
$(“#”+self.id+”).show()
(不需要最后一个“”,所以$(“#”+self.id).show()
,但这不是问题所在)
self
是this
这是openWith
函数,它显然没有DOM元素ID。其中没有ID
属性用于popUpFormulario
所以$(“#“+self.ID+”)
将给出$(“#未定义”)
它不存在。您想做什么,你期望self.id是什么