获取一个属性 id,设置为另一个属性 id
我目前正在使用 scriptaculous 和原型将元素从一个 div 拖放到另一个 div,并根据删除的元素的“src”附加一个新元素,从中创建一个新的可拖动元素。
我需要做的是在创建新元素后将删除的元素的 id 分配给新元素。
我尝试了很多不同的方法,这是最新的:
$$('.image').each(function(stack) {
new Draggable(stack, { revert: true, ghosting: true });
});
......
onDrop: function(stack) {
var added = new Element('img');
added.src = stack.readAttribute('src');
var imageid = stack.identify();
added.setAttribute('id', imageid);
显然我有点新手,想象一下我现在还很遥远。 感谢任何帮助。
I'm currently using scriptaculous and prototype to drag/drop elements from one div to another, and append a new Element based on the 'src' of the element that is dropped, creating a new draggable out of it.
What I need to do is assign the id of the dropped element to the new one once it is created.
I've tried a ton of different approaches, here is the latest:
$('.image').each(function(stack) {
new Draggable(stack, { revert: true, ghosting: true });
});
...
onDrop: function(stack) {
var added = new Element('img');
added.src = stack.readAttribute('src');
var imageid = stack.identify();
added.setAttribute('id', imageid);
obviously I'm a bit of a novice, and imagine I am way off by now. Appreciate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的大部分代码看起来都很合理,但我想确保放置的 div 对象是可放置的。 Draggable 类没有 onDrop 回调函数。 如果您查看文档,就会发现有 onStart、onDrag、change 和 onEnd。 尝试使用 onEnd 代替。
http://wiki.github.com/madrobby/scriptaculous/draggable
http://wiki.github.com/madrobby/scriptaculous/droppables
Most of your code seems sound however I wanted to make sure that div object being dropped on is Droppable. The Draggable class doesn't have an onDrop callback function. If you look at the documentation it has an onStart, onDrag, change, and onEnd. Try using onEnd instead.
http://wiki.github.com/madrobby/scriptaculous/draggable
http://wiki.github.com/madrobby/scriptaculous/droppables