/* 页面交互公共效果 */
// 加载头尾代码片段
(function(win, $) {
var categorynum = $("#viewguid").attr("value");
if(categorynum == '000'){
$("#"+categorynum).addclass("active");
}else{
categorynum = categorynum.substr(4);
$("#"+categorynum).addclass("active");
}
var include = function(cfg) {
this.cfg = cfg;
this._init();
};
include.prototype = {
constructor: include,
_init: function() {
var c = this.cfg;
if (c.async !== false) c.async = true;
this.$container = $('#' + c.id);
},
fetch: function() {
var c = this.cfg,
self = this;
return $.ajax({
url: c.src,
type: 'get',
datatype: 'html',
async: c.async,
success: function(html) {
self.$container.html(html);
c.onload && c.onload(html);
}
});
}
};
// 需要引入的代码片段 ★头尾是js加载的,头尾的js要写在回调函数里★
var includes = [{
id: 'header',
src: '/header.inc.html',
onload: function() {
var categorynum = $("#viewguid").attr("value");
if(categorynum == '000'){
$("#"+categorynum).addclass(active);
}else{
categorynum = categorynum.substr(4);
$("#"+categorynum).addclass("active");
}
$('[placeholder]').placeholder();
}
}, {
id: 'footer',
src: '/footer.inc.html',
onload: function() {
// console.log('...footer loaded...');
}
}];
$.each(includes, function(i, cfg) {
if ($('#' + cfg.id).length) {
new include(cfg).fetch();
}
});
$(".ewb-content").append('
* 本网站任何信息未经许可不得转载或用于商业用途,违者必究!
');
}(this, jquery));
//其他公用js
(function($) {
if (!window.util) {
window.util = {};
}
/*
* 序列化表单元素,区别于jquery 的serialize和serializearray方法
*/
$.fn.serializeobject = function() {
var o = {};
var a = this.serializearray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
$.extend(util, {
/* 获取url地址参数
* prop:参数名
*/
geturlparams: function(prop) {
var params = {},
query = location.search.substring(1),
arr = query.split('&'),
rt;
$.each(arr, function(i, item) {
var tmp = item.split('='),
key = tmp[0],
val = tmp[1];
if (typeof params[key] == 'undefined') {
params[key] = val;
} else if (typeof params[key] == 'string') {
params[key] = [params[key], val];
} else {
params[key].push(val);
}
});
rt = prop ? params[prop] : params;
return rt;
},
// 适配f9中的response格式
ajax: function(options) {
options = $.extend({}, {
type: 'post',
datatype: 'json',
datafilter: function(data, type) {
if (type == 'json') {
data = json.parse(data);
// todo: 这里可以对data做些统一处理,权限处理等
// data = data.userarea;
if (typeof data == 'object') {
data = json.stringify(data);
}
}
return data;
},
error: util._ajaxerr
}, options);
//options.url = srcboot.getpath(options.url);
return $.ajax(options);
},
// empty function
noop: function() {},
// 去除html标签中的换行符和空格
clearhtml: function(html) {
return html.replace(/(\r\n|\n|\r)/g, "")
.replace(/[\t ]+\[\t ]+\<")
.replace(/\>[\t ]+$/g, ">");
},
_ajaxerr: function(jqxhr, textstatus, errorthrown) {
console.error('status: %s, error: %s', textstatus, errorthrown);
}
});
}(jquery));
function searchall(){
var searchkey =encodeuricomponent($('#searchkey').val());
tiaojian = "?wd="+searchkey+"&cnum=017";
window.open("/search/fullsearch.html"+tiaojian);
}