如何避免复制HTML&内联编辑中的CSS内容使用可信属性

时间:2016-04-11 09:18:57

标签: javascript jquery html css angularjs

在Inline Edit中,我们正在尝试复制粘贴自己的内容,但它会自行复制html内容。

请找到以下屏幕截图:

enter image description here

如何避免复制html内容和样式?

我们只需要复制粘贴内容。

DEMO

HTML

<td><a href="" contentEditable="true" ng-model="fName">John</a></td>

Angular:

var myApp = angular.module('myApp', []);


myApp.directive('contenteditable', function() {
    return {
        require: 'ngModel',
        link: function(scope, elm, attrs, ctrl) {
            // view -> model
            elm.bind('blur', function() {
                scope.$apply(function() {
                    ctrl.$setViewValue(elm.text());
                });
            });

            // model -> view
            ctrl.render = function(value) {
                elm.html(value);
            };

            // load init value from DOM
            ctrl.$setViewValue(elm.text());

            elm.bind('keydown', function(event) {
                console.log("keydown " + event.which);
                var esc = event.which == 27,
                    el = event.target;

                if (esc) {
                        console.log("esc");
                        ctrl.$setViewValue(elm.text());
                        el.blur();
                        event.preventDefault();                        
                    }

            });

        }
    };
})

CSS:

a[contentEditable] {
  cursor: pointer;
  background-color: white;
    padding: .2em;
}
a[contentEditable]:focus {
  cursor: pointer;
  background-color: #D0D0D0;
    border: 1px solid red;
  padding: .2em;
}

0 个答案:

没有答案