HTML 5--contentEditableプロパティdocument.execCommand()関数テキスト太斜体などの設定

1541 ワード




	
	Document


	




//                   
//     document.execCommand  .
// document.execCommand("backcolor","false","red"); 
//      :      、             、      




//              
function Editor(selector){
	//jquery    $       
	this.$editor = $(selector);
	//           _    Javascript           
	this.bindEvents_();
}
Editor.prototype.bindEvents_ = function(){
	//              ,           
	this.$editor.on('click', 'button', function(event) {
		var id = event.currentTarget.id;
		switch(id){
			case "bold" :
			//               
				document.execCommand('bold');
				break;
			case "i" :
				document.execCommand('italic');
				break;
			case "underline" :
				document.execCommand('underline');
				break;
			case "bgcolor" :
				document.execCommand('backcolor','false','red');
				break;
		}
	});
}
new Editor('#btnGroup'); //