繁体   English   中英

javascript / php图像定位系统问题

[英]Problems with javascript/php image positioning system

我正在从事一个涉及在虚拟客厅中移动产品的项目,我具有以下功能

<a href="javascript:void(0)" onclick="sendxandy( <? echo $_SESSION['numberOfProducts']; ?> )">Save Positions of Products</a>

然后函数如下:

`
function sendxandy(productAmount)
{
       if (productAmount == 1)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y;
       }
       if (productAmount == 2)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y;
       }
       if (productAmount == 3)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y + 
   "&xthree= " + dd.elements.image3.x + "&ythree=" + dd.elements.image3.y;
       }
       if (productAmount == 4)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y + 
   "&xthree= " + dd.elements.image3.x + "&ythree=" + dd.elements.image3.y + 
   "&xfour= " + dd.elements.image4.x + "&yfour=" + dd.elements.image4.y;
       }
       if (productAmount == 5)
       {
   location.href="homeview.php?x=" + dd.elements.image1.x + "&y=" + dd.elements.image1.y + 
   "&xtwo= " + dd.elements.image2.x + "&ytwo=" + dd.elements.image2.y + 
   "&xthree= " + dd.elements.image3.x + "&ythree=" + dd.elements.image3.y + 
   "&xfour= " + dd.elements.image4.x + "&yfour=" + dd.elements.image4.y +
   "&xfive= " + dd.elements.image5.x + "&yfive=" + dd.elements.image5.y;
}
`

并且该功能将一直持续到图像10。因此,您可以看到图像的坐标保存在URL中,这样我就可以在php中访问它们,我的下一个功能是

<a class="code" href="javascript:void(0);" onclick="moveProduct(<? echo $_SESSION['numberOfProducts']; ?>)">Move Images Back</a>

在这里我有这个(由于某些原因,moveTo变量是php变量,该显示无法打印代码,moveTo是另一个脚本提供的另一个函数):

`function moveProduct(moveAmount)
{
    if (moveAmount == 1)
    {   
        if(window.dd && dd.elements) 
        {
        dd.elements.image1.moveTo(, );
        }
    }
    if (moveAmount == 2)
    {   
        if(window.dd && dd.elements) 
        {
        dd.elements.image1.moveTo(, );
        dd.elements.image2.moveTo(, );
        }
    }
    if (moveAmount == 3)
    {   
        if(window.dd && dd.elements) 
        {
        dd.elements.image1.moveTo(, );
        dd.elements.image2.moveTo(, );
        dd.elements.image3.moveTo(, );
        }
    }

`现在我知道我的循环结构太糟糕了:),但是请忍受我。 发生什么事在moveProduct函数内部,无论最后一个“ moveAmount ==”是什么,图像都将仅以该数字进行重定位。 例如,如果我具有上述功能,则仅会记住三张图像,而不是一两个或四个或五个,而是三个。 我实际上有十个项目,因此我将上述功能设置为十个项目,并且仅会记住10张图像。 当我在页面上没有10个项目时运行功能moveProduct时,什么都没有发生,就像我将加载一张图像,移动它,单击“保存”一样,一切看起来都很好,但是当我将其移回记住的坐标时,什么也没有发生。

请帮助任何建议,将不胜感激

嘿,我想通了,php变量返回空白值,这使js函数完全失败了:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM