Javascript 未定义函数,don';我不知道为什么
这是密码。按钮1和按钮2显示为未定义Javascript 未定义函数,don';我不知道为什么,javascript,function,Javascript,Function,这是密码。按钮1和按钮2显示为未定义 $('.game_time').each(function() { // bind_toggle($(this).find('a.preview_tweets.selected'), $(this).find('.with_tweets'), // $(this).find('a.collapse_tweets'), $(this).find('.without_tweets')); button1.click = fun
$('.game_time').each(function() {
// bind_toggle($(this).find('a.preview_tweets.selected'), $(this).find('.with_tweets'),
// $(this).find('a.collapse_tweets'), $(this).find('.without_tweets'));
button1.click = function() {
if ($(this).find('a.preview_tweets.selected').hasClass('open')){
} else {
if ($(this).find('a.preview_tweets.selected').length == 0) {
get_preview_tweets('<%= game.away_team.url %>,<%= game.home_team.url %>',
3, '<%= game.id %>');
}
$(this).find('a.preview_tweets.selected').show()
$(this).find('a.preview_tweets.selected').addClass('open');
}
}
button2.click = function() {
if ($(this).find('a.preview_tweets.selected').hasClass('open')){
$(this).find('a.preview_tweets.selected').hide();
} else {
}
}
});
$('.game_time')。每个(函数(){
//绑定_切换($(this.find('a.preview_tweets.selected'),$(this.find('.with_tweets'),
//$(this.find('a.collapse_tweets'),$(this.find('.without_tweets'));
button1.click=函数(){
if($(this.find('a.preview\u tweets.selected')).hasClass('open')){
}否则{
if($(this.find('a.preview\u tweets.selected')。长度==0){
获取“预览”推文(“,”,
3, '');
}
$(this.find('a.preview\u tweets.selected').show()
$(this).find('a.preview_tweets.selected').addClass('open');
}
}
button2.click=函数(){
if($(this.find('a.preview\u tweets.selected')).hasClass('open')){
$(this.find('a.preview_tweets.selected').hide();
}否则{
}
}
});
我对Javascript一无所知,所以如果有什么显而易见的事情,我很抱歉
button1.click = function() {}
这将被这样调用:button1.click()
如果你愿意,你可以把它改成按钮1
button1 = function() {}
看起来您正在使用jQuery。这些是您试图引用的按钮的
id
s吗?如果是,请尝试$(“#button1”)。单击
如果页面上有两个按钮,id为button1和button2,则可以使用:
$('#button1').click(function(){
//Your code here
});
在哪里声明了
button1
和button2
呢?在我看来,这里也没有定义var button1=$(“#button1”)可能是代码>?如果button1
是一个元素,而不是button1。单击,使用$(“#button1”)。单击button1和button2在另一个html文档中声明为锚定类。按钮1应该是“预览推文”,按钮2应该是“折叠推文”