我已经写了一些代码,如下所示。我无法弄清楚为什么hideDialog()可以工作,但showDialog()不起作用。任何人都可以告诉我我的代码有什么问题,或者给我一些搜索信息?感谢:)
以下是错误消息:
未捕获的TypeError:$(...)。showDialog不是函数
function showDialog(){
this.animate({
top:50
},{
duration:400,
effect:'slide',
easing:'easeOutBack'
});
}
function hideDialog(){
this.animate({
top:-200
},{
duration:400,
effect:'slide',
easing:'easeInBack'
});
}
function initSetting(){
$('.form-control').change(function(){
$('#myAlertDialog').showDialog();
$('#myAlertDialog').find('btnOk').on('click',function(){
$('#myAlertDialog').hideDialog();
});
});
}
答案 0 :(得分:0)
尝试像这样重新构建代码,
function showDialog($this){
$this.animate({
top:50
},{
duration:400,
effect:'slide',
easing:'easeOutBack'
});
}
function hideDialog($this){
$this.animate({
top:-200
},{
duration:400,
effect:'slide',
easing:'easeInBack'
});
}
function initSetting(){
$('.form-control').change(function(){
showDialog($('#myAlertDialog'));
$('#myAlertDialog').find('btnOk').on('click',function(){
hideDialog($('#myAlertDialog'));
});
});
}
或read this question知道如何在jquery之上创建用户定义的函数。
答案 1 :(得分:0)
使用-(BOOL)doStringsMatch:(NSString*)first second:(NSString*)second
{
first = [first stringByReplacingOccurrencesOfString:@"-" withString:@""];
first = [first stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"First String: %@", first);
second = [second stringByReplacingOccurrencesOfString:@"-" withString:@""];
second = [second stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"Second String: %@", second);
return ([first isEqual:second]);
}
而非onclick="deleteHandler(\''+url+'\');"
。
使用$.fn.showDialog()
代替function showDialog()
。
您正在尝试扩展jQuery原型。
请参阅What is $.fn.function和Plugins How to Create a Basic Plugin
答案 2 :(得分:0)
尝试像这样构建代码。进一步,阅读jQuery中这和$(this)之间的区别。
function showDialog(item){
$(item).animate({
top:50,
duration:400,
effect:'slide',
easing:'easeOutBack'
});
} // end of showDialog
function hideDialog(item){
$(item).animate({
top:-200,
duration:400,
effect:'slide',
easing:'easeInBack'
});
} // end of hideDialog
function initSetting(){
$('.form-control').change(function(){
showDialog($('#myAlertDialog'));
$('#myAlertDialog').find('btnOk').on('click',function(){
hideDialog($('#myAlertDialog'));
});
});
}
// btnOK should have a # or . for the identifier.
// if the click event does not work, then try with the delegate() function. http://api.jquery.com/delegate/