Reputation: 63
What is the basic method of styling text inside input boxes? Can you show me the most simple example of how to change text color separately?
Upvotes: 3
Views: 1175
Reputation: 2631
Very simply:
window.document.designMode = “On”;
document.execCommand(‘ForeColor’, false, ‘red’);
For more detail:
http://shakthydoss.com/javascript/html-rich-text-editor/
and then
http://shakthydoss.com/javascript/stxe-html-rich-text-editor/
Upvotes: 3
Reputation: 7413
There are 4 approaches you can adopt
insertHtml
to preview div. Trix uses the same approach but programmatically.Example
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'
]
})
Upvotes: 0