再点击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
最满意答案
你需要一个中间
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 beforestrcat
ing, or you can directlysprintf
the number torv
, 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
.)
相关问答
更多-
在C中使用strcat(Using strcat in C)[2023-11-28]
更改 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 ...
-
如何使用strcat()函数?(How to use strcat() function?)[2022-07-08]
在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 overflow?)[2024-02-01]
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和strcat有什么问题?(What's wrong with this simple code using strings, malloc and strcat?)[2023-07-15]
您的代码通过写入只读存储并尝试写入其末尾来展示未定义的行为。 您的malloc理念是朝着正确方向迈出的一步。 但是,您应该使用strcpy将"Hello"复制到新分配的内存中。 此外,您需要考虑计划追加的字符串的大小,以及计算动态分配大小时的空终止符。 显然,您还需要在程序结束时释放所有已分配的内存: char** nameList; nameList = malloc(4*sizeof(char*)); nameList[0] = malloc(12); strcpy(nameList[0], "Hell ... -
strcat的错误(Errors with strcat)[2022-03-09]
你将字符文字(包装在' )作为第二个参数传递给某些strcat strcat(group[leftIndex],'_'); 但是strcat期望第二个参数(以及它的第一个参数)是char*类型,而不是char ,它们都需要以NUL终止。 这就是投诉人抱怨的原因。 使用字符串文字而不是字符文字来解决问题: strcat(group[leftIndex],"_"); memset(group[i], 0, 256 + 1); 有一个错误。 使用 memset(group[i], 0, 256); 或更好 ...