変換前
変換後
ソースコード
HTML
<span>変換前</span>
<textarea id="src" style="height:20em;"></textarea>
<input id="exec" type="button" value="実行" />
<span id="message1"></span>
<span>変換後</span>
<textarea id="dst" style="height:20em;"></textarea>
<input id="clear" type="button" value="クリア" />
JavaScript
$(function(){
function htmlesc(instr){
var outstr = instr;
outstr = outstr.replace(/&/g, ("&"+"amp;"));
outstr = outstr.replace(/</g, ("&"+"lt;"));
outstr = outstr.replace(/>/g, ("&"+"gt;"));
outstr = outstr.replace(/"/g, ("&"+"quot;"));
outstr = outstr.replace(/'/g, ("&"+"#x27;"));
outstr = outstr.replace(/`/g, ("&"+"#x60;"));
return outstr;
};
$("#exec").click(function(){
var text = $("#src").val();
text = htmlesc(text);
$("#dst").val(text);
$('#dst').select();
document.execCommand('copy');
$('#message1').text('結果をクリップボードにコピーしました。').show().fadeOut(2000);
});
$("#clear").click(function(){
$("#src").val("");
$("#dst").val("");
});
});
CocoonのカスタムJavaScriptに埋め込み
コメント