情况说明:服务开启后,第一次 访问页面,下面的功能可以正常运行,离开页面后,再次访问,下面的功能失效
为什么 呢?
$(document).ready(initPage);
function initPage(){
var edit = $(".edit");
var prev = $(".preview");
var txtBox = $("#topic_body") ;
var insert_code = $(".insert_code");
edit.on("click" , edit_f);
prev.on("click" , preview_f);
insert_code.on("click" , insert_code_f);
function insert_code_f(){
var language = $(this).attr("data-lang") ;
var caret_pos = txtBox.caret();
var prefix_break = "" ;
if (txtBox.val().length > 0){
prefix_break = "\n" ;
}
var src_merged = prefix_break + "```" + language + "\n\n```\n" ;
var source = txtBox.val() ;
txtBox.val(source + src_merged) ;
}
function preview_f(){
prev.addClass('active') ;
edit.removeClass('active');
txtBox.hide();
}
function edit_f(){
edit.addClass('active') ;
prev.removeClass('active');
txtBox.show();
}
}