[英]jQuery draggable function causes error in PrimeFaces JSF page
I am using jQuery in JSF to make a drag and drop feature. 我在JSF中使用jQuery进行拖放功能。 The draggable function works fine independently, but when out in a JSF page, it throws an error!
Draggable函数可以独立正常运行,但是在JSF页面中时会引发错误!
Here is the code: 这是代码:
function attachClickEvents() {
$(".circle").on('click', function(event){
event.stopPropagation();
event.stopImmediatePropagation();
$(".circle").each(function(){
$(this).removeClass("selected");
});
$(this).addClass("selected");
// $(this).draggable({containment:'parent',drag: handleDragStop});
$(this).draggable({containment:$(this).parent().parent().parent()});
});
}
What is surprising is, $(this).addClass("selected");
令人惊讶的是,
$(this).addClass("selected");
piece works fine and the appearance of that marker is changed. 件工作正常,并且标记的外观已更改。
But the next statement throws an error: 但是下一条语句将引发错误:
Uncaught TypeError: $(...).draggable is not a function
未捕获的TypeError:$(...)。draggable不是函数
I am using the JSF recommended way of including jQuery: 我正在使用JSF建议的包括jQuery的方法:
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
<h:outputScript library="primefaces" name="jquery/jquery-plugins.js" target="head" />
What's wrong? 怎么了?
the problem was I was explicitly adding a jquery version in my code. 问题是我在代码中明确添加了一个jQuery版本。 Also another developer who was working independently also included another version of jquery.
另一个独立工作的开发人员还包括另一个版本的jquery。 All 3 were conflicting.
这三个都冲突。 I removed explicit inclusion of jquery and included the one provided by prime faces , it started working.
我删除了显式包含的jquery并包含了prime face提供的那个,它开始起作用。 Always make sure you dont have multiple inclusion of jquery of different versions.Hope this helps some one
始终确保您不包含多个不同版本的jquery。希望这可以帮助一些人
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.