HTML5的拖拽时间 ondragstart

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>dragable</title>
</head>
<body>
<h1  draggable="true">time</h1>
<span id="clock" draggable="true">time_span</span>
<img src="12.png" />
<textarea cols="60" rows="20"></textarea>
<script>
(function(){
    var clock = document.getElementById('clock');
    var icon = new Image();
    icon.src = "12.png";
    
    function displayTime(){
        var now = new Date();
        clock.innerHTML = now.getMinutes();
        setTimeout(arguments.callee,6000);
    };
    displayTime();
    
    clock.ondragstart = function(ev){
        var dt = ev.dataTransfer; //event里面有一个dataTransfer,这栋西很重要,setData,就是将数据保存到一个缓冲中,然后,就可以放到textarea看到数据了
        dt.setData("Text",Date(),"\n");
        if(dt.setDargImage)dt.setDragImage(icon,0,0)
    }
})()
</script>
</body>
</html>

//来自于西牛叔 p472页

posted @ 2014-01-06 23:27  方方和圆圆  阅读(1511)  评论(0编辑  收藏  举报

再过一百年, 我会在哪里?