English 中文(简体)
第一次点击时不得分解的功能
原标题:Function not toggling on first click

我撰写了一个网页,有来自外地的网页,使用户能够选择一个灯塔,把图像与图像联系起来。 你可以强调的有表格,现有颜色正在另一页装上一个文件箱,但问题一是,首先,在第二次点击之后,纽芬兰语才有色,而第二个问题一则是,我不知道如何只用一顿语,因此,基本上我只想一把一只彩票连接起来,因此不必同时强调多彩。 我 m忙,因此,将非常感激任何帮助。 I m 采用jquery作为 Java本框架。 接近底层的职能并不完全相关,但认为包括这些职能。

   var from_post = false; 
   var addOrRemove = true;

     $(document).ready(function() {

          $("#gallery").load( http://localhost/index.php/site/gallerys_avalible/ #gallerys_avalible , function() {
          $( li ).click(function(e) {

            //  console.log($( li ).index((this)));


             //  e.preventDefault();

                $(this).toggle(
                function(){
                    $(this).css( background-color ,  #CC0000 );
                     console.log( backgroudn red );
                },
                function(){
                    $(this).css( background-color ,  #00A8F0 ); 
                           console.log( backgroudn blue );
                });


                return false;
              });  

            });

           /* $( li ).live( click , function(e) {  

            });
        */
            $( #addNew ).click(function () {
                console.log( i got called );
                $( #new_form ).fadeIn(1000); 
            });

            $( form ).submit(function() {

                if(from_post) {
                    //submit form

                    return true; 

                } else {

                    //dont submit form. 
                    return false; 

                }
            });

        });

感谢任何人花时间帮助我这样做。

最佳回答

你们要履行太多的职能。

第二个问题:

document.onLoad(function(){
    $("#gallery").load( http://… );
    $("#gallery > li").toggle(function(){
        function(){$(this).css( background-color ,  #CC0000 );},
        function(){$(this).css( background-color ,  ORIGINAL_COLOUR );}
    });
});

最好增加/取消一个类别,而不是适用cs。

document.onLoad(function(){
    $("#gallery").load( http://… );
    $("#gallery > li").click(function(){
        $("#gallery > li").toggleClass("active");
        //this will add .active if it s not there, or remove it if it s already there
    });
});

这也将处理任何点击问题。

此外,还有j Query :not(。 如果你想选择其他一切。

问题回答

why don t you simply use .toggle

 $( li ).toggle(function() {         

                function(){
                    $(this).css( background-color ,  #CC0000 );
                     console.log( backgroudn red );
                },
                function(){
                    $(this).css( background-color ,  #00A8F0 ); 
                           console.log( backgroudn blue );
                });   




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签