在输入框内设置文本样式的基本方法是什么?你能告诉我一个如何分别改变文字颜色的最简单的例子吗?
答案 0 :(得分:3)
非常简单:
window.document.designMode = “On”;
document.execCommand(‘ForeColor’, false, ‘red’);
更多细节:
http://shakthydoss.com/javascript/html-rich-text-editor/
然后
http://shakthydoss.com/javascript/stxe-html-rich-text-editor/
答案 1 :(得分:0)
您可以采用4种方法
insertHtml
以预览div。 Trix使用相同的方法,但以编程方式。示例强>
angular.module("myApp", [])
.directive("click", function () {
return {
restrict: "A",
link: function (scope, element, attrs) {
element.bind("click", function () {
scope.$evalAsync(attrs.click);
});
}
};
})
.controller("Example", function ($scope) {
$scope.supported = function (cmd) {
var css = !!document.queryCommandSupported(cmd.cmd) ? "btn-succes" : "btn-error"
return css
};
$scope.icon = function (cmd) {
return (typeof cmd.icon !== "undefined") ? "fa fa-" + cmd.icon : "";
};
$scope.doCommand = function (cmd) {
if ($scope.supported(cmd) === "btn-error") {
alert("execCommand(“" + cmd.cmd + "”)\nis not supported in your browser");
return;
}
val = (typeof cmd.val !== "undefined") ? prompt("Value for " + cmd.cmd + "?", cmd.val) : "";
document.execCommand(cmd.cmd, false, (cmd.val || ""));
}
$scope.commands = commands;
$scope.tags = [
'Bootstrap', 'AngularJS', 'execCommand'
]
})