019.xhtml (1304B)
1 <?xml version="1.0" encoding="utf-8"?> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>Text input selection drag and drop: setting dropzone attribute ondragstart</title> 5 <style type="text/css"> 6 div 7 {display:inline-block; 8 vertical-align:top; 9 background-color:olive; 10 color:white; 11 padding:20px; 12 width:100px; 13 height:100px;} 14 div:nth-child(2) 15 {background-color:green;} 16 div:nth-child(3) 17 {background-color:teal;} 18 </style> 19 <script type="application/ecmascript"> 20 var effects = ['copy','move','link']; 21 function selectText() 22 {document.querySelector('input').select()} 23 function dropSelection(event,element) 24 {document.querySelectorAll('div')[element].appendChild(document.createTextNode((event.dataTransfer.dropEffect == effects[element])?' PASS ':' FAIL ')); 25 selectText();} 26 function start(event) 27 {for(var i = 0; i != 3; i++) 28 {document.querySelectorAll('div')[i].setAttribute('dropzone',effects[i] + ' string:text/plain')} 29 } 30 </script> 31 </head> 32 <body onload="selectText()"> 33 <div ondrop="dropSelection(event,0)"/> 34 <div ondrop="dropSelection(event,1)"/> 35 <div ondrop="dropSelection(event,2)"/> 36 <p ondragstart="start(event)"><input value="Drag me" ondragstart="start(event)"/></p> 37 <p>You should be able to drag selection and drop it onto any of the green boxes.</p> 38 </body> 39 </html>