zoukankan      html  css  js  c++  java
  • jQuery禁用剪切、复制、粘贴功能

    jQuery是我们在WEB开发中使用最多的JS类库,他可以很方便的帮助我们实现很多绚丽的功能。本文将给大家介绍JQuery的一种小功能,用来禁用文本框的剪切、复制、粘贴功能,完整的页面代码如下:

    <!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" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <title>JQuery禁用文本框的剪切、复制、粘贴功能演示代码</title>
        <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
        <style>
            .main { 900px;margin: 0 auto;height: 900px;border: 1px solid #ccc;padding: 20px;}
            .header{height: 100px;}
            .footer{height: 100px;bottom: 0px;}
            .heading{color: #FF5B5B;margin: 10px 0;padding: 10px 0;font-family: trebuchet ms;}
        </style>
    </head>
    <body>
    <div class="main">
        <div class="heading">JQuery禁用文本框的剪切、复制、粘贴功能演示</div>
        <div id='dv1'>
            <table>
                <tr><td>姓名</td><td><input type='text' id='txt_input' /></td></tr>
                <tr><td>简介</td><td> <textarea id='textarea_inp'></textarea></td></tr>
                <tr><td>提示:</td><td><div id='div_cnt'>在上面文本框中执行剪切、复制、粘贴试试吧!!</div></td></tr>
            </table>
        </div>
    </div>
    <script>
        $(document).ready(function() {
            $('#txt_input').bind("cut copy paste", function(e) {
                alert('Copy Paste is disabled');
                e.preventDefault();
            });
            $('#textarea_inp').bind("cut copy paste", function(e) {
                alert('Copy Paste is disabled');
                e.preventDefault();
            });
            $('#div_cnt').bind("cut copy paste", function(e) {
                alert('Copy Paste is disabled');
                e.preventDefault();
            });
        });
    </script>
    </body>
    </html>
  • 相关阅读:
    计算最大公约数 Exercise05_14
    求满足n^2>12000的n的最大值 Exercise05_13
    依赖注入(DI)
    spring容器
    基于xml文件的bean的配置
    小试牛刀 spring的HelloWorld
    spring 装配Bean
    spring介绍
    hibernate相关类与接口
    hibernate 预习
  • 原文地址:https://www.cnblogs.com/crxis/p/13063952.html
Copyright © 2011-2022 走看看