简体   繁体   中英

Draggable div property is not working in IE

I have created a draggable DIV by code-

<div id="Age"
     draggable="true"
     ondragstart="drag(event)" width="50px" height="25px"
     style="background-color:Green;">Age</div>

The DIV is working fine in Firfox, Crome, but not working in IE, Opera. Is there any other way to create a draggable DIV that works in all browsers? Thanks,

EDITED

<script  language="javascript" type="text/javascript">
function drag(ev) {
    ev.dataTransfer.setData("Text", ev.target.id);
   }</script>

Can anyone provede me the solution with jQuery?

As you have asked for jquery solution :-
Add these two JS files in your page :-

  <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
  <script type="text/javascript" src="http://code.jquery.com/ui/1.8.18/jquery-ui.min.js"></script>

HTML:-

<div id="draggable" class="ui-widget-content">
    <p>Drag me around</p>
</div>

JS:-

  $(function() {
        $( "#draggable" ).draggable({
            drag: function(event, ui) {}
        });
    });

See the Fiddle :-
and it is working in IE7 too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM