/*html
<tr>
<td width="50" align="right"><div class="divSty2"><label>请选择从业方向:</label></div></td>
<td>
<select id="txtjobDirection" class="easyui-combotree" multiple style="width:200px;"></select>
</td>
</tr>
<tr>
<td align="right" ><label >请选择区域:</label></td>
<td >
<div class="divSty5">
<label>省<select id="txtProvince" class="easyui-combobox" name="txtProvince" style="width:200px;"
editable="false" data-options="valueField:‘id‘,textField:‘text‘"></select></label>
<label>市/县<select id="txtCity" class="easyui-combotree" multiple style="width:200px;"
></select></label>
</div>
</td>
</tr>
*/
/**
* 判断非空
* @param val
* @returns {Boolean}
*/
function isEmpty(val) {
val = val.trim();
if (val == null)
return true;
if (val == undefined || val == ‘undefined‘)
return true;
if (val == "")
return true;
if (val.length == 0)
return true;
if (!/[^(^\s*)|(\s*$)]/.test(val))
return true;
return false;
};
function isNotEmpty(val) {
return !isEmpty(val);
};
/**
* 从业方向下拉选择
*/
function queryJobDirection(){
$.get("queryJobDirection.action",function(obj){
var catN = obj.data.length;
var data = [{"id":"root","text":"全部","checked":true,children:[]}];
for(var i=0;i<catN;i++){
var childsN = obj.data[i].childs.length;
var res ={"id":"","text":obj.data[i].childs[0].catalogName,children:[]};
for(j=0;j<childsN;j++){
var children = {"id":obj.data[i].childs[j].id,"text":obj.data[i].childs[j].name};
res.children.push(children);
}
data[0].children.push(res);
}
$("#txtjobDirection").combotree("loadData",data);
});
}
/**
* 省下拉选择
*/
function province(){
$.get("queryRootArea.action",function(obj){
var catN = obj.data.length;
var data = [];
for(var i=0;i<catN;i++){
var res ={"id":obj.data[i].id,"text":obj.data[i].name};
data.push(res);
}
$("#txtProvince").combobox("loadData",data);
});
}
/**
* 点击省事件
*/
function eventProvince(){
$("#txtProvince").combobox({
onSelect: function(param){
var parentId =$("#txtProvince").combobox("getValue");
$.post("queryChildArea.action",{"parent":parentId},function(obj){
var catN = obj.data.length;
var data = [];
for(var i=0;i<catN;i++){
var res ={"id":obj.data[i].id,"text":obj.data[i].name,children:[]};
data.push(res);
}
$("#txtCity").combotree("loadData",data);
});
}
});
}
/**
* 点击市事件
*/
function eventCity(){
$(‘#txtCity‘).combotree({
onSelect: function(node){
if(node.children.length == 0){
$.post("queryChildArea.action",{"parent":node.id},function(obj){
var catN = obj.data.length;
var data = [];
for(var i=0;i<catN;i++){
var res ={"id":obj.data[i].id,"text":obj.data[i].name};
data.push(res);
}
$(‘#txtCity‘).combotree("tree").tree(‘append‘,{parent:node.target,data:data});
});
}
}
});
}
/**
* 删数组个下标
*/
Array.prototype.baoremove = function(dx){
if(isNaN(dx)||dx>this.length){return false;}
this.splice(dx,1);
}
/**
* 添加数组中的值
*/
Array.prototype.insert = function (index, item) {
this.splice(index, 0, item);
};
/**
* 推送按钮事件
*/
function eventBtn(){
$("#btnPush").click(function(){
var jobDirections = $(‘#txtjobDirection‘).combotree(‘getValues‘);
if(jobDirections.length == 0){
$.messager.alert("提示","请选择从业方向!!","info");
return;
}else{
if(jobDirections[0] == "root"){
jobDirections = ["root"];
}else{
for(var key in jobDirections){
if(jobDirections[key] == ""){
jobDirections.baoremove(key);
}
}
}
}
jobDirections = JSON.stringify(jobDirections)
var Province = $(‘#txtProvince‘).combobox(‘getValue‘);
if(isEmpty(Province)){
$.messager.alert("提示","请选择区域!!","info");
return;
}
var Citys = $(‘#txtCity‘).combotree(‘getValues‘);
if(Citys.length == 0){
Citys = [Province];
}else{
Citys.insert(0,Province);
}
Citys = JSON.stringify(Citys);
var InfoRate = $("input[name=‘rdoInfoRate‘]:checked").val();
var Identifion = $("input[name=‘rdoIdentifion‘]:checked").val();
var Business = $("input[name=‘rdoBusiness‘]:checked").val();
var Specialist = $("input[name=‘rdoSpecialist‘]:checked").val();
var Content = $.trim($("#txtContent").val());
var data ={
content:Content,
jobDirection:jobDirections,
area:Citys,
infoRate:InfoRate,
identifionAuth:Identifion,
businessAuth:Business,
specialistAuth:Specialist
}
$.post("addManpowerBlog.action",data,function(obj){
if (obj.status == 0) {
$.messager.alert("提示", obj.message, "info");
$("#txtContent").val("");
} else {
$.messager.alert("错误", obj.message, "error");
}
});
});
}
/**
* 点击市县下拉面板显示的时候触发。
*/
function showPanel(){
$("#txtCity").combotree({
onShowPanel: function(){
var Citys = $("#txtCity").combotree("tree").tree("getRoots");
if(Citys.length == 0){
$.messager.alert("提示","请选择省!!","info");
}
}
});
}
本文出自 “新手学习中” 博客,谢绝转载!
原文地址:http://9322128.blog.51cto.com/9312128/1691589