当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


HTML ondragenter用法及代码示例


当内容可拖动时,HTML中的ondragenter事件属性起作用。通过将可拖动属性值设置为true来制作元素。 draggable属性只能采用true或false值。

用法:

<element ondragenter = "script">

属性值:此属性包含单值脚本,该脚本在调用ondragenter事件属性时起作用。

范例1:

<!DOCTYPE html> 
<html> 
    <head> 
        <title> 
            HTML ondragenter Event Attribute 
        </title> 
          
        <!-- script to add background color -->
        <script> 
            function MyFunction() { 
                document.getElementById("geeks").style.backgroundColor 
                            = "green"; 
            } 
        </script> 
    </head> 
      
    <body id = "geeks" style = "text-align:center"> 
          
        <!-- ondragenter event call here -->
        <h1 ondragenter = "MyFunction()" draggable = "true"> 
            GeeksforGeeks 
        </h1> 
          
        <p>Drag heading content to change background color</p> 
    </body> 
</html>                    

输出:
拖动内容之前:

拖动内容后:



范例2:

<!DOCTYPE html> 
<html> 
    <head> 
        <title> 
            HTML ondragenter Event Attribute 
        </title> 
          
        <script> 
            function dragenter_time() { 
                document.getElementById("geeks").innerHTML  
                    = "The date and time is:" + Date(); 
            } 
        </script> 
    </head> 
      
    <body> 
        <center> 
              
            <!-- ondragenter event call here -->
            <p id = "geeks" ondragenter="dragenter_time()"
                draggable = "true">Drag to know time 
            </p> 
        </center> 
    </body> 
</html>                    

输出:
拖动内容之前:

拖动内容后:

支持的浏览器:下面列出了ondragenter事件属性支持的浏览器:

  • 谷歌浏览器4.0
  • Internet Explorer 9.0
  • Firefox 3.5
  • Safari 6.0
  • Opera 12.0




相关用法


注:本文由纯净天空筛选整理自roshalmoraes大神的英文原创作品 HTML | ondragenter Event Attribute。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。