帮助我从原型转向 jquery
window.onload = function() {
$A($('draggables').getElementsByTagName('p')).each(
function(item) {
new Draggable(
item,
{
revert: true
}
);
}
);
Droppables.add(
'droparea0',
{
hoverclass: 'hoverActive',
onDrop: moveItem
}
);
// Set drop area by default non cleared.
$('droparea0').cleared = false;
}
function moveItem( draggable,droparea){
$(droparea).highlight({startcolor: '#999999', endcolor: '#f3f0ca' });
if (!droparea.cleared) {
droparea.innerHTML = '';
droparea.cleared = true;
}
draggable.parentNode.removeChild(draggable);
droparea.appendChild(draggable);
}
你好,我正在从原型转向 Jquery,现在我无法成功地进行转换,最后需要一些帮助。有人可以帮我将上面的原型 js 代码翻译为 jquery 并添加一些注释以便我可以遵循吗?我会非常感激。是的,原型是一项有点艰苦的工作,但在我完全了解 jquery 之前,很难将这一举动从我的脑海中抹去。
window.onload = function() {
$A($('draggables').getElementsByTagName('p')).each(
function(item) {
new Draggable(
item,
{
revert: true
}
);
}
);
Droppables.add(
'droparea0',
{
hoverclass: 'hoverActive',
onDrop: moveItem
}
);
// Set drop area by default non cleared.
$('droparea0').cleared = false;
}
function moveItem( draggable,droparea){
$(droparea).highlight({startcolor: '#999999', endcolor: '#f3f0ca' });
if (!droparea.cleared) {
droparea.innerHTML = '';
droparea.cleared = true;
}
draggable.parentNode.removeChild(draggable);
droparea.appendChild(draggable);
}
Hi, I'm moving from prototype to Jquery and right now I've being unsuccessfuly able to do the transition and finally need some help. can some pne please help me to translate the above prototype js code to jquery put some comments to it so I can follow? I will really appreciate. Yes, prototype is a bit hard work but until I get my head into jquery completely it will be hard to get that move out of my head.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如已经提到的,jQueryUI 是你的朋友。给定以下 HTML:
您可以使用以下 jQuery 和 jQueryUI 来获得接近您正在做的事情。
在这里工作 jsFiddle: http://jsfiddle.net/2F8YE/
As already mentioned, jQueryUI is your friend. Given the following HTML:
You can use the following jQuery and jQueryUI to get something close to what you are doing.
Working jsFiddle here: http://jsfiddle.net/2F8YE/
首先,在 jQuery 中,您应该使用 $(function(){...}) 而不是 window.onload (jquery 从这里开始;D)
只需查看 jQueryUI 示例 http://jqueryui.com/demos/droppable/
first of all in jQuery you should use $(function(){...}) instead of window.onload (jquery starts here ;D)
just look at the jQueryUI sample http://jqueryui.com/demos/droppable/