2016-11-17 29 views
-1

我想使用SapUI5和JQuery $("#draggable").draggable();函數拖動我的HTML頁面上的一些div。 (我想使用JQuery draggable()函數)。這個問題是 - 他們互相干擾 - SAPUI5庫也有一個名爲draggable的varibale(我想用jQuery draggable()函數)。SAPUI5和JQuery可拖動 - 拒絕混合

,結果我得到Uncaught TypeError: $(...).draggable is not a function(…)

如何解決呢?我的代碼在下面..它模擬了這個問題。請注意,一旦我刪除SAPUI5的腳本標記,它工作正常,我可以拖動分區..

在此先感謝!

<!doctype html> 
 
<html lang="en"> 
 
<head> 
 

 
    <title>jQuery UI Draggable - Default functionality</title> 
 
    <style> 
 
     #draggable { width: 150px; height: 150px; padding: 0.5em; border:1px; } 
 
    </style> 
 
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
 
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
 

 

 

 

 
    <script id='sap-ui-bootstrap' 
 
      type='text/javascript' 
 
      src='https://sapui5.hana.ondemand.com/1.38.10/resources/sap-ui-core.js' 
 
      data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.m,sap.ui.ux3" 
 
      data-sap-ui-theme="sap_bluecrystal" 
 
    > 
 
    </script> 
 

 
    <script> 
 
     $(function() { 
 
      $("#draggable").draggable(); 
 
     }); 
 
    </script> 
 
</head> 
 
<body> 
 

 
<div id="draggable"> 
 
    <p>Drag me around</p> 
 
</div> 
 

 

 
</body> 
 
</html>

+1

看看我的答案[這裏](https://stackoverflow.com/questions/37584845/uncaught-typeerror-cannot -use功能於操作者對搜索換位置在-undefin/37585277#37585277) – Dopedev

回答

3

你應該在底部

<!doctype html> 
<html lang="en"> 
<head> 

    <title>jQuery UI Draggable - Default functionality</title> 
    <style> 
     #draggable { width: 150px; height: 150px; padding: 0.5em; border:1px; } 
    </style> 




    <script id='sap-ui-bootstrap' 
      type='text/javascript' 
      src='https://sapui5.hana.ondemand.com/1.38.10/resources/sap-ui-core.js' 
      data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.m,sap.ui.ux3" 
      data-sap-ui-theme="sap_bluecrystal" 
    > 
    </script> 

    <script> 
     $(function() { 
      $("#draggable").draggable(); 
     }); 
    </script> 
</head> 
<body> 

<div id="draggable"> 
    <p>Drag me around</p> 
</div> 


    <script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
</body> 
</html> 
2

其他選項移動Jquery的腳本是導入第三方庫。

<script> 
    $.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-core'); 
    $.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-widget'); 
    $.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-mouse'); 
    $.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-draggable'); 

     $(function() { 
     $("#draggable").draggable(); 
    }); 
</script> 

你可以在一個功能包的調用,使之少醜陋=)