让对象留在脚本化的可放置对象中

发布于 2024-07-30 14:16:45 字数 1064 浏览 7 评论 0原文

当我查看人们添加到 Scriptaculous 的内容时,我发现了一些有趣的代码,并且我正在尝试根据我的目的修改它。 我几乎完成了所有工作,除了当我粘贴放置处理程序代码时,我的页面停止加载。

以下是相关的片段:

对于可拖动:

for (i=0; i<=50; i++){
     Squad = 'Squad' + i
     if($(Squad)){
          new Draggable(Squad,{revert:true});

对于可放置:

Droppables.add('ToEast', {
     accept: ["Nurse","Squad","Doctor"], 
     onDrop:function(e){DropHandler(e,'ToEast')}
});

drophandler:

 function DropHandler(element,el){
     var newnode  = document.createElement('img'); 
     var classname = element.className;
     newnode.src="images/"+IdCatcher+".jpg";
     newnode.id = IdCatcher;  
     $(el).appendChild(newnode);
     newnode.setAttribute("class", 'classname');
     newnode.setAttribute("className", 'classname);
     new Draggable(newnode.id,{revert:true});
     element.parentNode.removeChild(element);
 }

我用“alert()”替换了代码,它开始工作正常,所以最后一个块中的某些内容不能很好地工作。 我必须修改他们的很多代码才能使其与当前版本的 scriptaculous 兼容,但我不太熟悉,所以它可能与旧代码有关? 或者可能只是有什么问题,我不够好看到的。

I found some interesting code when I was looking at things that people had added on to Scriptaculous, and I'm trying to modify it for my purposes. I got nearly all of it working, except when I paste in the drop handler code, my page stops loading.

Here's the relevant snipits:

For draggables:

for (i=0; i<=50; i++){
     Squad = 'Squad' + i
     if($(Squad)){
          new Draggable(Squad,{revert:true});

For Droppables:

Droppables.add('ToEast', {
     accept: ["Nurse","Squad","Doctor"], 
     onDrop:function(e){DropHandler(e,'ToEast')}
});

The drophandler:

 function DropHandler(element,el){
     var newnode  = document.createElement('img'); 
     var classname = element.className;
     newnode.src="images/"+IdCatcher+".jpg";
     newnode.id = IdCatcher;  
     $(el).appendChild(newnode);
     newnode.setAttribute("class", 'classname');
     newnode.setAttribute("className", 'classname);
     new Draggable(newnode.id,{revert:true});
     element.parentNode.removeChild(element);
 }

I replaced the code with "alert()" and it started working fine, so something in that last block isn't working well. I had to modify a lot of their code to make it work with the current version of scriptaculous, but i'm not all that familiar, so it could have something to do with old code? Or there could just be something wrong with it that I'm not good enough to see.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春庭雪 2024-08-06 14:16:45

您在该行末尾缺少结束引号:

newnode.setAttribute("className", 'classname);

如果仍然存在问题,我建议您尝试使用 Firebug< 调试脚本/a> 查看哪一行导致错误。

You are missing a closing quote on the end of this line:

newnode.setAttribute("className", 'classname);

If there's still a problem, I suggest you try debugging the script using Firebug to see which line causes an error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文