在jquery中,我将一个<li>元素附加到无序列表中.
我如何专注于新创建的<li>?
如果我执行以下操作:
$("ul").append('<li><input type="text" value="Hi!"></li>');
$("li:last").focus(); //doesn't work because new <li> isn't in dom yet
Run Code Online (Sandbox Code Playgroud)
如上所述,焦点不起作用.
我知道jquery 1.4.2有一个live()事件处理程序,它允许你加载事件处理程序来动态添加元素,但我不确定我做错了什么:
$(document).ready(function () {
$('li').live('load', function () {
alert("hi!");
$("li:last").focus();
});
});
Run Code Online (Sandbox Code Playgroud) 我在C#3.0中有一个基于struct的小型3D矢量类,它使用double作为基本单元.
一个例子:一个向量的y值是
-20.0 straight
Run Code Online (Sandbox Code Playgroud)
我减去一个y值为的向量
10.094999999999965
Run Code Online (Sandbox Code Playgroud)
y我期望的价值是
-30.094999999999963 (1)
Run Code Online (Sandbox Code Playgroud)
相反,我得到了
-30.094999313354492 (2)
Run Code Online (Sandbox Code Playgroud)
当我在一个单独的线程中进行整个计算时,我得到(1).调试器和VS快速监视器也会返回(1).但是,当我在一个线程中运行几次迭代然后从另一个线程调用该函数时,结果是(2).现在,调试器也返回(2)!
我们必须记住.NET JIT可能会将值写回内存(网站Jon Skeet),这会将精度从80位(FPU)降低到64位(双倍).但是,(2)的准确性远低于此.
vector类看起来基本上都是这样的
public struct Vector3d
{
private readonly double _x, _y, _z;
...
public static Vector3d operator -(Vector3d v1, Vector3d v2)
{
return new Vector3d(v1._x - v2._x, v1._y - v2._y, v1._z - v2._z);
}
}
Run Code Online (Sandbox Code Playgroud)
计算就像这样容易
Vector3d pos41 = pos4 - pos1;
Run Code Online (Sandbox Code Playgroud) 这个问题来自于需要确保我对代码所做的更改不会影响它输出到文本文件的值.理想情况下,我会滚动一个子来接收两个文件名,return 1或者return 0取决于内容是否相同,空格和所有内容.
鉴于文本处理是Perl的强项,比较两个文件并确定它们是否相同(代码低于未经测试)应该非常容易.
use strict;
use warnings;
sub files_match {
my ( $fileA, $fileB ) = @_;
open my $file1, '<', $fileA;
open my $file2, '<', $fileB;
while (my $lineA = <$file1>) {
next if $lineA eq <$file2>;
return 0 and last;
}
return 1;
}
Run Code Online (Sandbox Code Playgroud)
我能想到的唯一方法(没有CPAN模块)是打开有问题的两个文件,并逐行读取它们直到找到差异.如果没有找到差异,则文件必须相同.
但这种方法有限且笨拙.如果两个文件中的总行数不同怎么办?我应该打开和关闭以确定行数,然后重新打开以扫描文本?呸.
我没有看到perlfaq5中与此有关的任何内容.我希望远离模块,除非它们带有核心Perl 5.6.1发行版.
我在Linux(C/C++和POSIX线程)下有多线程编程的经验,但是最明显的情况有时非常复杂.
我的代码中有几个静态常量变量(全局和函数本地),我可以在不使用互斥锁的情况下从多个线程同时访问它们吗?因为我不修改它们应该没问题,但总是更好问.
我必须进行高速优化,因此即使像互斥锁一样快速操作也对我来说非常昂贵,特别是因为我的应用程序将从长循环中访问这些变量.
让我们想象一下非常简单的游戏...我们有一个迷宫和两个玩家试图通过互联网实时退出.
在每个移动游戏中,客户端应该将玩家的坐标发送到服务器并接受另一个客户端的当前坐标.怎么可能如此快速地进行这种交换(就像所有现代游戏一样).
好的,我们可以使用memcache或类似技术来减少服务器端的数据挖掘操作.我们也可以使用最快的网络服务器等,但我们仍然会遇到时间问题.
所以,问题是......
在这种情况下如何使用with语句?
f_spam = open(spam,'r')
f_bar = open(eggs,'r')
...
do something with these files
...
f_spam.close()
f_bar.close()
Run Code Online (Sandbox Code Playgroud)
文件编号可能大于2.
基本上我有三个领域,我正在创建一个新的,三个组合制作一个可邮寄的地址; 问题是某些字段包含空值并将myString添加到null只会在sql中生成null.
所以这是我的代码,任何人都可以使它更干净吗?它仍然看起来很漂亮!
UPDATE [mydb].[dbo].[Account]
SET [Billing Street] = CASE
WHEN [(Billing Address 1)] is null and [(Billing Address 2)] is null THEN [(Billing Address 3)]
WHEN [(Billing Address 1)] is null and [(Billing Address 3)] is null THEN [(Billing Address 2)]
WHEN [(Billing Address 2)] is null and [(Billing Address 3)] is null THEN [(Billing Address 1)]
WHEN [(Billing Address 1)] is null THEN [(Billing Address 2)] + ' ' + [(Billing Address 3)]
WHEN [(Billing Address 2)] is …Run Code Online (Sandbox Code Playgroud) 根据MSDN MethodRental Class允许更改动态模块的方法体.但是由于它的局限性,我无法想到它的实际用法.谷歌也没有帮助我.
任何想法可以用于什么类?
我使用函数fork(),exec()...
但是如何编译这个程序而不包括一些额外的头文件(比如sys/types.h,sys/wait.h).
我使用ubuntu 10.04和gcc版本4.4.3
#include <stdio.h>
#include <stdlib.h>
int main()
{
pid_t pid;
printf("before fork\n");
pid = fork();
if(pid == 0)
{
/*child*/
if(execvp("./cpuid", NULL))
{
printf("error\n");
exit(0);
}
}
else
{
if(wait(NULL) != -1)
{
printf("ok\n");
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个拆分View控制器,左侧有一个表视图控制器.当我单击表格单元格的详细信息披露按钮时,如何在弹出窗口中显示操作表?
.net ×2
c ×2
action ×1
c# ×1
c++ ×1
comparison ×1
controller ×1
dynamic ×1
file ×1
focus ×1
game-engine ×1
ipad ×1
javascript ×1
jquery ×1
linux ×1
mmo ×1
multiplayer ×1
online-game ×1
perl ×1
popover ×1
pthreads ×1
python ×1
reflection ×1
sql-server ×1