我试图在用户点击按钮时激活jQuery-ui .draggable-function。包含脚本并且没问题,因为当我使用以下代码时一切正常:
<script>
function test() {
$( ".bord" ).draggable({ containment: ".rom", scroll: false });
}
$("#bordplassering").click(function() {
test();
});
</script>
然后.bord-class是可拖动的。但是我希望它只在你点击一个按钮时才可以拖动,所以我使用这个代码:
brand_matches
这里问题开始......这给了我以下错误:
&#34; TypeError:$(...)。draggable不是函数&#34;
为什么!?
答案 0 :(得分:1)
请像这样使用:(你必须在document.ready函数中移动你的点击功能)
<script>
function test() {
$( ".bord" ).draggable({ containment: ".rom", scroll: false });
}
$( document ).ready(function() {
$("#bordplassering").click(function() {
test();
});
});
</script>
答案 1 :(得分:1)
试试这个结构:
<script>
$(function() {
$(".bord").draggable({containment: ".rom", scroll: false});
});
</script>
但在你开始之前:
$
$()
$.draggable
另外,您应该阅读DOM和DOM ready event。
答案 2 :(得分:0)
我建议仅在开始时应用draggble函数,然后在单击时使用启用和禁用方法使其无法和禁用。
http://api.jqueryui.com/draggable/#method-disable
使用document.ready
create table `appointment` (
`slot` varchar (90),
`remarks` varchar (180)
);
insert into `appointment` (`slot`, `remarks`) values('2016-03-01 08:00','');
insert into `appointment` (`slot`, `remarks`) values('2016-03-01 09:00','');
insert into `appointment` (`slot`, `remarks`) values('2016-03-01 10:00','');
insert into `appointment` (`slot`, `remarks`) values('2016-03-01 11:00','Tennis with Mark');
insert into `appointment` (`slot`, `remarks`) values('2016-03-01 12:00','Lunch at home');
insert into `appointment` (`slot`, `remarks`) values('2016-03-01 13:00','Programming');
insert into `appointment` (`slot`, `remarks`) values('2016-03-01 14:00','');
insert into `appointment` (`slot`, `remarks`) values('2016-03-01 15:00','');
insert into `appointment` (`slot`, `remarks`) values('2016-03-01 16:00','');
insert into `appointment` (`slot`, `remarks`) values('2016-03-01 17:00','');
...
...
delete from `appointment` where slot < '2016-02-01' and remarks='';
答案 3 :(得分:0)
感谢大家的帮助。正如在这里的评论中指出的那样,问题是jQuery是在footer.php文件中第二次加载的。
但是肯定有许多改进代码的好主意。