/**
* @param {Object} id ‘cname‘
* @param {Object} pointout ‘请输入收藏夹名称‘
*/
function pointoutListener(id, pointout) { //为cname添加单击时间和失去焦点的监听器
var myinput = document.getElementById(id);
addListener(myinput, "click", function(){
var value1 = $(‘#‘+id).val().replace(/(^\s*)|(\s*$)/g,"");
var style = $(this).attr(‘style‘);
if (style == ‘‘ || style==undefined) {
$(this).attr(‘style‘,‘background:#fff;color:#000;‘);
myinput.value = "";
}
})
addListener(myinput, "blur", function(){
var value1 = $(‘#‘+id).val().replace(/(^\s*)|(\s*$)/g,"");
if(value1==‘‘ || value1==null){
$(this).attr(‘style‘, ‘‘);
myinput.value = pointout;
}
})
}
function addListener(element, e, fn){
if (element.addEventListener) {
element.addEventListener(e, fn, false);
}
else {
element.attachEvent("on" + e, fn);
}
}
$(function(){
pointoutListener(‘cname‘, ‘请输入收藏夹名称‘); //‘cname‘ ‘请输入收藏夹名称‘
pointoutListener(‘sname‘, ‘输入关键词搜索‘); //‘cname‘ ‘请输入收藏夹名称‘
});
jquery 文本框失去焦点显示提示信息&&单击置空文本框