使用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 {width: 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>

  

转载于:https://www.cnblogs.com/hupan508/p/6373093.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值