首页 \ 问答 \ 再点击jQuery(Second click jQuery)

再点击jQuery(Second click jQuery)

我试图制作一个动画,当我点击一个搜索图标时,它会淡入搜索输入并添加一个类以使其更宽。 问题是我不知道在搜索输入已经显示之后如何在第二次点击时使其变为fadeOut:

这是我的代码:

    $('#menu_search').click(function(){
        $('.search_input').fadeIn().toggleClass('full');
    });


    <li id="menu_search">
        <a href="javascript:void(0)"></a>
        <div class="search_input_container">
            <input type="text" class="search_input" value="Buscar">
        </div>
    </li>


        &#menu_search{
            background: url('../img/sprites.png') #000 2px 2px;
            width: 34px;
            height: 28px;
            padding: 0;
            margin-right: 0;
            a{
                display: inline-block;
                width: 100%;
                height: 100%;
            }
            .search_input_container{
                width: 500px;
                height: 30px;
                position: absolute;
                z-index: 20;
                left: -466px;
                .search_input{
                    float: right;
                    width: 100px;
                    background: #ffffff;
                    height: 30px;
                    border: none;
                    .round_corners();
                    .animate();
                    display: none;
                    &.full{
                        width: 772px;
                        display: block;
                    }
                }
            }
        }

I´m trying to make an animation that when I click on a search icon, it fadeIn the search input and add a class to make it wider. The problem is that I don´t know how to make it fadeOut in the second click after the search input it´s already displayed:

this is my code:

    $('#menu_search').click(function(){
        $('.search_input').fadeIn().toggleClass('full');
    });


    <li id="menu_search">
        <a href="javascript:void(0)"></a>
        <div class="search_input_container">
            <input type="text" class="search_input" value="Buscar">
        </div>
    </li>


        &#menu_search{
            background: url('../img/sprites.png') #000 2px 2px;
            width: 34px;
            height: 28px;
            padding: 0;
            margin-right: 0;
            a{
                display: inline-block;
                width: 100%;
                height: 100%;
            }
            .search_input_container{
                width: 500px;
                height: 30px;
                position: absolute;
                z-index: 20;
                left: -466px;
                .search_input{
                    float: right;
                    width: 100px;
                    background: #ffffff;
                    height: 30px;
                    border: none;
                    .round_corners();
                    .animate();
                    display: none;
                    &.full{
                        width: 772px;
                        display: block;
                    }
                }
            }
        }

原文:https://stackoverflow.com/questions/15269581
更新时间:2024-04-22 16:04

最满意答案

你需要一个中间char数组来打印strcat前的数字,或者你可以直接将数字rv ,但是为此你需要一个指向结尾的指针,

char *rv = malloc(2048);
char *rv_end = rv;
...
rv_end += sprintf(rv_end, "%d", fib(num));

并在将其他内容附加到缓冲区时更新rv_end指针。

(感谢jthill使用sprintf的返回值进行改进。)


You need either an intermediate char array to print the number to before strcating, or you can directly sprintf the number to rv, but for that you need a pointer to the end,

char *rv = malloc(2048);
char *rv_end = rv;
...
rv_end += sprintf(rv_end, "%d", fib(num));

and also update the rv_end pointer when appending other things to the buffer.

(Thanks to jthill for the improvement using the return value of sprintf.)

相关问答

更多
  • 更改 char *message = "\n\nHTTP/1.1 "; 至 char message[1024]; strcpy(message,"\n\nHTTP/1.1 "); 你应该没问题,总共消息长度为1023。 编辑:(根据mjy的评论)。 以这种方式使用strcat是获得缓冲区溢出的好方法。 您可以随时编写一个检查缓冲区大小和传入字符串添加长度的小函数来克服此问题,或者在动态缓冲区上使用realloc。 国际海事组织,负责程序员检查使用正确的缓冲区大小,如sprintf和其他C字符串函数 ...
  • 不,它没有“正确”地做到这一点; 你的代码非常破碎。 编译器在发出警告时并不是很有趣,他们通常知道他们在说什么,而是你需要弄清楚你的代码有什么问题导致它触发警告。 因为应该没有。 在您的情况下,此代码例如: char *session = (char*) ( rand() % (9999 - 1000 + 1) + 1000 ); 无效,并且使用session就像它指向有效字符串一样,很可能会调用未定义的行为。 您不能将事物“转换”为C中的字符串,除非它们是以0开头的字节数组,用于描述预期编码中的字符。 ...
  • 您没有分配空间来保存输入字符串的两个副本。 strcpy复制字符串。 strcat将一个字符串附加到另一个字符串。 malloc在堆上分配应该是free()字节。 char *two(char *foo); int main() { char * ptr = two("foo"); printf("The value of two(\"foo\") is %s", ptr); free(ptr); } char *two(char *foo) { char * ptr ...
  • 在C语言中,函数strcat不会创建包含连接字符串的新字符数组。 它将第二个字符串中的字符附加到第一个字符数组的第一个字符串,前提是它有足够的元素来存储新字符。 否则,该函数将尝试覆盖导致未定义行为的字符数组之外的内存。 因此,在第一个程序中有效使用该函数可以采用以下方式 #include #include int main(int argc, const char *argv[]) { char s1[11] = "12345"; char s2 ...
  • 如果我理解你的问题是正确的,你会发现程序有未定义的行为,因为无法保存字符串“Solaris”与“Linux”连接。 所以你要找的答案不是“这是未定义的行为”,而是: 它为什么会这样 在处理未定义的行为时,我们无法对正在发生的事情做出一般性解释。 对于不同的编译器(或编译器版本)等,它可能在不同的系统上执行不同的操作或执行不同的操作。 因此,人们经常说,尝试解释具有未定义行为的程序中发生的事情是没有意义的。 好吧 - 这是正确的。 但是 - 有时你可以找到适合你的特定系统的解释 - 只要记住它是特定于你的系统 ...
  • 你需要一个中间char数组来打印strcat前的数字,或者你可以直接将数字rv ,但是为此你需要一个指向结尾的指针, char *rv = malloc(2048); char *rv_end = rv; ... rv_end += sprintf(rv_end, "%d", fib(num)); 并在将其他内容附加到缓冲区时更新rv_end指针。 (感谢jthill使用sprintf的返回值进行改进。) You need either an intermediate char array to prin ...
  • strcat()将一个字符串中的字符附加到另一个字符串。 目标字符串已修改。 所以strcat(str1, str2)修改str1也包含str2的内容。 由于没有为str1分配足够的内存来包含两个字符串中的字符,因此会导致溢出。 strcat() appends the characters from one string to another string. The target string is modified. So strcat(str1, str2) modifies str1 to also ...
  • 您没有为生成的连接字符串分配足够的空间; 当您在结束时写入时,您将调用未定义的行为(在这种情况下,可能是堆损坏)。 更改malloc以分配strlen(argv[2]) + strlen(".txt") + 1这样你就有了足够大的缓冲区来保存整个字符串。 You didn't allocate enough space for the resulting concatenated string; when you write past the end you invoke undefined behavio ...
  • 您的代码通过写入只读存储并尝试写入其末尾来展示未定义的行为。 您的malloc理念是朝着正确方向迈出的一步。 但是,您应该使用strcpy将"Hello"复制到新分配的内存中。 此外,您需要考虑计划追加的字符串的大小,以及计算动态分配大小时的空终止符。 显然,您还需要在程序结束时释放所有已分配的内存: char** nameList; nameList = malloc(4*sizeof(char*)); nameList[0] = malloc(12); strcpy(nameList[0], "Hell ...
  • 你将字符文字(包装在' )作为第二个参数传递给某些strcat strcat(group[leftIndex],'_'); 但是strcat期望第二个参数(以及它的第一个参数)是char*类型,而不是char ,它们都需要以NUL终止。 这就是投诉人抱怨的原因。 使用字符串文字而不是字符文字来解决问题: strcat(group[leftIndex],"_"); memset(group[i], 0, 256 + 1); 有一个错误。 使用 memset(group[i], 0, 256); 或更好 ...

相关文章

更多

最新问答

更多
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 高考完可以去做些什么?注意什么?
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • Flask中的自定义中止映射/异常(Custom abort mapping/exceptions in Flask)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 怎么在《我的世界》游戏里面编程
  • .NET可移植可执行文件VS .NET程序集(.NET Portable Executable File VS .NET Assembly)
  • 搜索字符串从视图中键入两个字段的“名字”和“姓氏”组合(Search Strings Typed from View for Two Fields 'First Name' and 'Last Name' Combined)
  • 我可以通过配置切换.Net缓存提供程序(Can I switch out .Net cache provider through configuration)
  • 在鼠标悬停或调整浏览器大小之前,内容不会加载(Content Does Not Load Until Mouse Hover or Resizing Browser)
  • 未捕获的TypeError:auth.get不是函数(Uncaught TypeError: auth.get is not a function)
  • 如何使用变量值创建参数类(How to create a parameter class with variant value)
  • 在std :: deque上并行化std :: replace(Parallelizing std::replace on std::deque)
  • 单元测试返回Connection对象的方法(Unit Test for a method that returns a Connection object)
  • rails:上传图片时ios中的服务器内部错误(rails: server internal error in ios while uploading image)
  • 如何在Android中构建应用程序警报[关闭](How build an application Alarm in Android [closed])
  • 以编程方式连接到Windows Mobile上的蓝牙耳机(Programmatically connect to bluetooth headsets on Windows Mobile)
  • 在两个不同的SharedPreference中编写并获得相同的结果(Writing in two different SharedPreference and getting the same result)
  • CSS修复容器和溢出元素(CSS Fix container and overflow elements)
  • 在'x','y','z'迭代上追加数组(Append array on 'x', 'y', 'z' iteration)
  • 我在哪里可以看到使用c ++源代码的UML方案示例[关闭](Where I can see examples of UML schemes with c++ source [closed])
  • SQL多个连接在与where子句相同的表上(SQL Multiple Joins on same table with where clause)
  • 位字段并集的大小,其成员数多于其大小(Size of bit-field union which has more members than its size)
  • 我安装了熊猫,但它不起作用(I installed pandas but it is not working)
  • Composer - 更改它在env中使用的PHP版本(Composer - Changing the version of PHP it uses in the env)
  • 使用JavaFX和Event获取鼠标位置(Getting a mouse position with JavaFX and Event)
  • 函数调用可以重新排序(Can function calls be reordered)
  • 关于“一对多”关系的NoSQL数据建模(NoSQL Data Modeling about “one to many” relationships)
  • 如何解释SBT错误消息(How to interpret SBT error messages)
  • 调试模式下的Sqlite编译器错误“初始化程序不是常量”(Sqlite compiler errors in Debug mode “initializer is not a constant”)