Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.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 未定义函数,don';我不知道为什么_Javascript_Function - Fatal编程技术网

Javascript 未定义函数,don';我不知道为什么

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

这是密码。按钮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 = 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应该是“折叠推文”