我想在JavaScript中使用XMLHttpRequest发送一些数据.
假设我在HTML中有以下表单:
<form name="inputform" action="somewhere" method="post">
<input type="hidden" value="person" name="user">
<input type="hidden" value="password" name="pwd">
<input type="hidden" value="place" name="organization">
<input type="hidden" value="key" name="requiredkey">
</form>
Run Code Online (Sandbox Code Playgroud)
如何在JavaScript中使用XMLHttpRequest编写等效代码?
我按下按钮时试图让UIView摇晃.
我正在调整我在http://www.cimgf.com/2008/02/27/core-animation-tutorial-window-shake-effect/上找到的代码.
但是,通过尝试调整以下代码来动摇UIView,它不起作用:
- (void)animate {
const int numberOfShakes = 8;
const float durationOfShake = 0.5f;
const float vigourOfShake = 0.1f;
CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animation];
CGRect frame = lockView.frame;
CGMutablePathRef shakePath = CGPathCreateMutable();
CGPathMoveToPoint(shakePath, NULL, CGRectGetMinX(frame), CGRectGetMinY(frame));
for (int index = 0; index < numberOfShakes; ++index) {
CGPathAddLineToPoint(shakePath, NULL, CGRectGetMinX(frame) - frame.size.width * vigourOfShake, CGRectGetMinY(frame));
CGPathAddLineToPoint(shakePath, NULL, CGRectGetMinX(frame) + frame.size.width * vigourOfShake, CGRectGetMinY(frame));
}
CGPathCloseSubpath(shakePath);
shakeAnimation.path = shakePath;
shakeAnimation.duration = durationOfShake;
[lockView.layer addAnimation:shakeAnimation forKey:@"frameOrigin"];
}
Run Code Online (Sandbox Code Playgroud) 我试图移动UIView与用户的触摸有关.
这就是我现在所拥有的:
int oldX, oldY;
BOOL dragging;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(window.frame, touchLocation)) {
dragging = YES;
oldX = touchLocation.x;
oldY = touchLocation.y;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(window.frame, touchLocation) && dragging) {
CGRect frame;
frame.origin.x = (window.frame.origin.x + touchLocation.x - oldX);
frame.origin.y = (window.frame.origin.y + touchLocation.y - oldY);
window.frame = …Run Code Online (Sandbox Code Playgroud) 我有一个1920x100的图像,它插在我页面的顶部:
<img src="./Resources/Images/banner.jpeg" style="position:absolute; top:0px; left:0px; height:100px; width:100%;" name="top">
Run Code Online (Sandbox Code Playgroud)
我希望这样,当页面水平调整大小时,图像不会随页面缩小,而是保留在屏幕的中心,如下所示:

这似乎是一件很容易实现的简单事情,但我还没有找到解决方案.
我可以将图像放在div中,并将div的左侧位置设置为 - (1920-pageWidth)/ 2,但这将依赖于JavaScript.我正在寻找一个更清洁的解决方案(如果有的话),只是为了最大限度地减少页面的复杂性,并最大限度地提高浏览器兼容性.
我可以使用任何CSS属性来实现这一目标,还是我完全错误地实现了这个目标?
任何帮助赞赏.
我只是想知道UINavigationBar的默认颜色是什么(在iPhone上).
我不能在任何地方找到它,并呼吁CGColorGetComponents()在navigationBar.tintColor.CGColorRef没有任何作用.
例如,如果我以编程方式将颜色设置为红色,我该如何将颜色恢复正常?
任何帮助赞赏.
我正在尝试使用64位Mac OS X Lion运行基本的汇编文件,使用默认安装Xcode的nasm和ld.
我编写了一个汇编文件,它打印了一个字符,然后我使用nasm构建它.
nasm -f elf -o program.o main.asm
但是,当我将它与ld链接时,它会因为相当多的错误/警告而失败:
ld -o program program.o
ld: warning: -arch not specified
ld: warning: -macosx_version_min not specificed, assuming 10.7
ld: warning: ignoring file program.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: symbol dyld_stub_binder not found, normally in libSystem.dylib
ld: entry point (start) undefined. Usually in crt1.o for inferred architecture x86_64
Run Code Online (Sandbox Code Playgroud)
所以,我试图纠正其中的一些问题,并没有取得任何进展.
这是我尝试过的一件事:
ld -arch i386 -e _start -o program program.o
我认为这会奏效,但我错了. …
我有一个XML文件,其中包含我想要使用的一些数据:
<?xml version="1.0" encoding="UTF-8" ?>
<items>
<item name="product" price="19.95" where="store">
This is the first product.
</item>
<item name="product2" price="39.95" where="online">
This is the second product.
</item>
<item name="product3" price="99.95" where="garagesale">
This is the third product.
</item>
</items>
Run Code Online (Sandbox Code Playgroud)
如果我制作了4个数组,一个用于名称,一个用于价格,一个用于购买,一个用于描述,如何将数据输入数组?
我想使用的NSXMLParser,但不能得到name,price,where或说明.
我一直坚持如何做到这一点.
任何帮助赞赏.
我希望能够将margin-bottom元素设置为其默认值.
请考虑以下示例,其中有些h1元素的各自margin-bottom样式属性设置为0:
h1 {
border: 1px solid red;
margin-bottom: 0;
}
p {
margin: 0;
}Run Code Online (Sandbox Code Playgroud)
<h1>First Heading</h1>
<p>Paragraph</p>
<h1 id="normal-margin">Second Heading</h1>
<p>Paragraph</p>Run Code Online (Sandbox Code Playgroud)
如何将margin-bottom值重置#normal-margin为其初始默认值?显然使用initial不起作用,因为初始值为margin-bottom0.
我意识到在这个简单的例子中我可以简单地添加:not(#normal-margin)到样式定义h1来解决问题.但是我想要一个解决方案,它可以"撤消"保证金并将其重置为初始值.
我想我将不得不将值硬编码到CSS中,这对我来说似乎有点便宜.这是解决这个问题的唯一方法吗?
如何在给定起始位置和长度的情况下替换字符串的子字符串?
我希望这样的事情:
var string = "This is a test string";
string.replace(10, 4, "replacement");
Run Code Online (Sandbox Code Playgroud)
这样string就相等了
"this is a replacement string"
Run Code Online (Sandbox Code Playgroud)
..但我找不到那样的东西.
任何帮助赞赏.
我想送一些NSData过Bluetooth通过GameKit.
虽然我已经GameKit设置好并且能够发送小消息,但我现在想要扩展并发送整个文件.
我一直在读你必须将大文件分成数据包然后单独发送它们.
所以我决定创建一个struct以便在另一端收到数据包时更容易解码数据包:
typedef struct {
const char *fileName;
NSData *contents;
int fileType;
int packetnumber;
int totalpackets;
} file_packet;
Run Code Online (Sandbox Code Playgroud)
但是,对于小文件(8KB或更少),我认为一个数据包就足够了.
所以对于一个数据包,我想我可以创建一个file_packet,设置它的属性,并通过-sendDataToAllPeers:withDataMode发送它:error:
NSData *fileData;
file_packet *packet = (file_packet *)malloc(sizeof(file_packet));
packet->fileName = [filename cStringUsingEncoding:NSASCIIStringEncoding];
packet->contents = [NSData dataWithContentsOfFile:selectedFilePath];
packet->packetnumber = 1;
packet->totalpackets = 1;
packet->fileType = 56; //txt document
fileData = [NSData dataWithBytes:(const void *)packet length:sizeof(file_packet)];
free(packet);
NSError *error = nil;
[self.connectionSession sendDataToAllPeers:fileData withDataMode:GKSendDataReliable error:&error];
if (error) {
NSLog(@"An error occurred: …Run Code Online (Sandbox Code Playgroud)