简体   繁体   English

为什么这适用于 IE,但不适用于 Firefox 或 Chrome?

[英]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.

相关问题 Onclick在IE或Firefox中无法使用,但在Chrome中可以使用 - Onclick not working in IE or Firefox but does work in Chrome 表单在Safari和Chrome中不起作用,但在ie和firefox中起作用 - Form doesn't work in Safari and Chrome, but does work in ie and firefox CSS动画在Firefox和IE上不起作用 - CSS animation does not work on Firefox and IE JavaScript时钟可在Chrome上使用,但不适用于Firefox或IE - JavaScript clock works on Chrome but doesn't work with Firefox or IE 为什么此注册表单可以在chrome和safari中使用ajax mysql插入,但不能在Firefox中使用? - Why does this registration form ajax mysql insert work in chrome and safari but not firefox? 为什么我的jquery链接在firefox和Microsoft Edge中有效,但在Google Chrome中不起作用? - Why does my jquery linking work in firefox and microsoft edge but not Google Chrome? 为什么在兼容打开的页面之间共享PHP会话似乎在FF中有效,而不是IE或Chrome? - Why does sharing PHP sessions between concurrently open pages seem to work in FF, but not IE or Chrome? 2种不同的输出(Chrome和IE / FIREFOX) - 2 Different outputs (Chrome and IE/FIREFOX) 查询适用于Firefox,但不适用于ie和chrome - query works on firefox but not on ie and chrome 表格适用于Chrome和IE,但不适用于Firefox - Form works in Chrome and IE but not firefox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM