0

我正在使用以下脚本在我的表单上禁用“剪切和粘贴”:

$(document).ready(function(){
  $('.employeeEmailConfirm, .emailConfirm').bind("cut copy paste",function(e) {
      alert('thou. shalt. not. PASTE!');
      e.preventDefault();
  });
});

取自以下线程:How to disable Paste (Ctrl+V) with jQuery?

但我不想显示我想显示隐藏 div 的“警报”。

但是,我的表单有单选按钮列表,并且根据选择的值显示或隐藏一些表单元素:

$(document).ready(function() {
// attach event to employee radio buttons 
$("span.isEmployee").find("input").click(function() {
    if ($(this).val() == "1") {
        $(".aboutyou").show();
        $(".yourdetails").show();
        $(".referrer").hide();
        $(".security").show();
        $(".signup").show();
        $("#emailTr").show();
        $("#employeeEmailMessage1").show();
        $("#employeeEmailMessage2").hide();
        $("#employeeEmailRetype").show();
        $("#nonemployeeEmail").hide();
        $("#nonemployeeEmailRetype").hide();
        $("#emailMessageSubBrand").show();
        SetEmailEnableDisable(true);
    } else {
        $(".aboutyou").show();
        $(".yourdetails").show();
        $(".referrer").show();
        $(".security").show();
        $(".signup").show();
        $("#emailTr").hide();
        $("#employeeEmailMessage1").hide();
        $("#employeeEmailMessage2").hide();
        $("#employeeEmailRetype").hide();
        $("#nonemployeeEmail").show();
        $("#nonemployeeEmailRetype").show();
        $("#emailMessageSubBrand").hide();
        SetEmailEnableDisable(false);
    }
});

如何将“剪切复制粘贴”脚本与我的显示/隐藏单选按钮列表结合起来?

我失败的尝试:

$(document).ready(function(){
  $('.employeeEmailConfirm, .emailConfirm').bind("cut copy paste",function(e) {
      alert('thou. shalt. not. PASTE!');
      $("span.isEmployee").find("input").click(function() {
          if ($(this).val() == "1") {
              $("#employeeEmailMessage2").show();
              } else {
                 $("#nonemployeeEmailMessage").show();
      e.preventDefault();
  });
});
4

1 回答 1

0

我让它工作:

$(document).ready(function() {
    $("span.isEmployee").find("input").click(function() {
        if ($(this).val() == "1") {
            $('.employeeEmail, .employeeEmailConfirm').bind("cut copy paste", function(e) {
                $("#employeeEmailMessage2").show();
                e.preventDefault();
            });
        } else {
            $('.email, .emailConfirm').bind("cut copy paste", function(e) {
                $("#nonemployeeEmailMessage").show();
                e.preventDefault();
            });
        }
    });
});
于 2012-10-08T23:28:45.060 回答