[英]Why does this work for IE but not for Firefox or Chrome?
I have created a signfield in javascript and php.我在 javascript 和 php 中创建了一个signfield。 The User can write in the field with the mouse.
用户可以用鼠标在字段中书写。 Javascript reads out the coordinates and sends them to a php script wich generates an image.
Javascript 读出坐标并将它们发送到 php 脚本,该脚本生成图像。 a new image is created every time the mouse is moved and it is moved into a div via javascript.
每次移动鼠标时都会创建一个新图像,并通过 javascript 将其移动到 div 中。 The problem is, that this works fine for IE 8, but it doesn't for Firfox or Chrome.
问题是,这适用于 IE 8,但不适用于 Firfox 或 Chrome。 Here is the relevant part of my code:
这是我的代码的相关部分:
.mousemove(function(e)
{
if(mouseDown)
{
//alert("debug");
//$("#debug").html($("#debug").html() + e.pageX + ", " + e.pageY + "<br>");
coordhdl.addCords(e.pageX - this.offsetLeft, e.pageY - this.offsetTop);
//$('#test').load('showCoordinates.php');
var coordinations = coordhdl.getCords();
$('#signature').remove();
//IMPORTANT LINE:
$('#test').prepend('<img id="signature" src="showCoordinates.php?cords=' + coordinations + '" alt="braso"');
}
});
I also tried to load an image that is on the filesystem instead using the php script.我还尝试使用 php 脚本加载文件系统上的图像。 That doesn't work either.
那也行不通。 So the problem can't be the communication between the javascript and the php script.
所以问题不可能是 javascript 和 php 脚本之间的通信。
I think it should be我认为应该是
$('#test').prepend('<img id="signature" src="showCoordinates.php?cords=' + coordinations + '" alt="braso"/>');
You missed />你错过了/>
Two problems: you're appending image with same ID and don't close the image tag.. try this instead:两个问题:您要附加具有相同 ID 的图像并且不关闭图像标签.. 试试这个:
var newImg = $("<img />").attr("src", "showCoordinates.php?cords=" + coordinations).attr("alt", "braso");
$('#test').prepend(newImg);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.