123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- //dom加载完成后执行的js
- $(function(){
- //全选的实现
- $(".check-all").click(function(){
- $(".ids").prop("checked", this.checked);
- });
- $(".ids").click(function(){
- var option = $(".ids");
- option.each(function(i){
- if(!this.checked){
- $(".check-all").prop("checked", false);
- return false;
- }else{
- $(".check-all").prop("checked", true);
- }
- });
- });
- //ajax get请求
- $('.ajax-get').click(function(){
- var target;
- var that = this;
- if ( $(this).hasClass('confirm') ) {
- if(!confirm('确认要执行该操作吗?')){
- return false;
- }
- }
- if ( (target = $(this).attr('href')) || (target = $(this).attr('url')) ) {
- $.get(target).success(function(data){
- if (data.status==1) {
- if (data.url) {
- updateAlert(data.info + ' 页面即将自动跳转~','alert-success');
- }else{
- updateAlert(data.info,'alert-success');
- }
- setTimeout(function(){
- if (data.url) {
- location.href=data.url;
- }else if( $(that).hasClass('no-refresh')){
- $('#top-alert').find('button').click();
- }else{
- location.reload();
- }
- },1500);
- }else{
- updateAlert(data.info);
- setTimeout(function(){
- if (data.url) {
- location.href=data.url;
- }else{
- $('#top-alert').find('button').click();
- }
- },1500);
- }
- });
- }
- return false;
- });
- //ajax post submit请求
- $('.ajax-post').click(function(){
- var target,query,form;
- var target_form = $(this).attr('target-form');
- var that = this;
- var nead_confirm=false;
- if( ($(this).attr('type')=='submit') || (target = $(this).attr('href')) || (target = $(this).attr('url')) ){
- form = $('.'+target_form);
- if ($(this).attr('hide-data') === 'true'){//无数据时也可以使用的功能
- form = $('.hide-data');
- query = form.serialize();
- }else if (form.get(0)==undefined){
- return false;
- }else if ( form.get(0).nodeName=='FORM' ){
- if ( $(this).hasClass('confirm') ) {
- if(!confirm('确认要执行该操作吗?')){
- return false;
- }
- }
- if($(this).attr('url') !== undefined){
- target = $(this).attr('url');
- }else{
- target = form.get(0).action;
- }
- query = form.serialize();
- }else if( form.get(0).nodeName=='INPUT' || form.get(0).nodeName=='SELECT' || form.get(0).nodeName=='TEXTAREA') {
- form.each(function(k,v){
- if(v.type=='checkbox' && v.checked==true){
- nead_confirm = true;
- }
- })
- if ( nead_confirm && $(this).hasClass('confirm') ) {
- if(!confirm('确认要执行该操作吗?')){
- return false;
- }
- }
- query = form.serialize();
- }else{
- if ( $(this).hasClass('confirm') ) {
- if(!confirm('确认要执行该操作吗?')){
- return false;
- }
- }
- query = form.find('input,select,textarea').serialize();
- }
- $(that).addClass('disabled').attr('autocomplete','off').prop('disabled',true);
- $.post(target,query).success(function(data){
- if (data.status==1) {
- if (data.url) {
- updateAlert(data.info + ' 页面即将自动跳转~','alert-success');
- }else{
- updateAlert(data.info ,'alert-success');
- }
- setTimeout(function(){
- $(that).removeClass('disabled').prop('disabled',false);
- if (data.url) {
- location.href=data.url;
- }else if( $(that).hasClass('no-refresh')){
- $('#top-alert').find('button').click();
- }else{
- location.reload();
- }
- },1500);
- }else{
- updateAlert(data.info);
- setTimeout(function(){
- $(that).removeClass('disabled').prop('disabled',false);
- if (data.url) {
- location.href=data.url;
- }else{
- $('#top-alert').find('button').click();
- }
- },1500);
- }
- });
- }
- return false;
- });
- /**顶部警告栏*/
- var content = $('#main');
- var top_alert = $('#top-alert');
- top_alert.find('.close').on('click', function () {
- top_alert.removeClass('block').slideUp(200);
- // content.animate({paddingTop:'-=55'},200);
- });
- window.updateAlert = function (text,c) {
- text = text||'default';
- c = c||false;
- if ( text!='default' ) {
- top_alert.find('.alert-content').text(text);
- if (top_alert.hasClass('block')) {
- } else {
- top_alert.addClass('block').slideDown(200);
- // content.animate({paddingTop:'+=55'},200);
- }
- } else {
- if (top_alert.hasClass('block')) {
- top_alert.removeClass('block').slideUp(200);
- // content.animate({paddingTop:'-=55'},200);
- }
- }
- if ( c!=false ) {
- top_alert.removeClass('alert-error alert-warn alert-info alert-success').addClass(c);
- }
- };
- //按钮组
- (function(){
- //按钮组(鼠标悬浮显示)
- $(".btn-group").mouseenter(function(){
- var userMenu = $(this).children(".dropdown ");
- var icon = $(this).find(".btn i");
- icon.addClass("btn-arrowup").removeClass("btn-arrowdown");
- userMenu.show();
- clearTimeout(userMenu.data("timeout"));
- }).mouseleave(function(){
- var userMenu = $(this).children(".dropdown");
- var icon = $(this).find(".btn i");
- icon.removeClass("btn-arrowup").addClass("btn-arrowdown");
- userMenu.data("timeout") && clearTimeout(userMenu.data("timeout"));
- userMenu.data("timeout", setTimeout(function(){userMenu.hide()}, 100));
- });
- //按钮组(鼠标点击显示)
- // $(".btn-group-click .btn").click(function(){
- // var userMenu = $(this).next(".dropdown ");
- // var icon = $(this).find("i");
- // icon.toggleClass("btn-arrowup");
- // userMenu.toggleClass("block");
- // });
- $(".btn-group-click .btn").click(function(e){
- if ($(this).next(".dropdown").is(":hidden")) {
- $(this).next(".dropdown").show();
- $(this).find("i").addClass("btn-arrowup");
- e.stopPropagation();
- }else{
- $(this).find("i").removeClass("btn-arrowup");
- }
- })
- $(".dropdown").click(function(e) {
- e.stopPropagation();
- });
- $(document).click(function() {
- $(".dropdown").hide();
- $(".btn-group-click .btn").find("i").removeClass("btn-arrowup");
- });
- })();
- // 独立域表单获取焦点样式
- $(".text").focus(function(){
- $(this).addClass("focus");
- }).blur(function(){
- $(this).removeClass('focus');
- });
- $("textarea").focus(function(){
- $(this).closest(".textarea").addClass("focus");
- }).blur(function(){
- $(this).closest(".textarea").removeClass("focus");
- });
- if($('.province').length>0){
- $('.province').each(function(){
- var ele=$(this);
- var provinceurl = BASE_URL+'/Home/Ajax/province';
- var selected_provinceid = $(this).attr('province-selected');
- //根据province表单上面的属性设置选中的城市id和省份id
- $.post(provinceurl,'',function(data){
- //var data = jQuery.parseJSON(result);
- var prohtml = '';
- $.each(data, function(i, value) {
- prohtml += '<option value="'+value.provinceid+'" '+(value.provinceid==selected_provinceid?'selected':'')+'>'+value.province+'</option>';
- });
- ele.empty().append(prohtml);
- ele.find('option:selected').change();
- });
- });
- }
- // 省份点击,城市更换
- $(".province").change(function(){
- var provinceid = $(this).val();
- var ele = $(this);
- if(provinceid){
- var cityurl = BASE_URL+'/Home/Ajax/city';
- var selected_cityid = $(this).attr('city-selected');
- var selected_areaid = $(this).attr('area-selected');
- $.post(cityurl,{provinceid:provinceid},function(data){
- var cityhtml = '<select class="select city" style="margin-left:10px;" name="cityid" area-selected="'+selected_areaid+'"><option value="0">选择城市</option>';
- $.each(data, function(i, value) {
- cityhtml += '<option value="'+value.cityid+'">'+value.city+'</option>';
- });
- cityhtml += '</select>';
- ele.parent().find('.city').remove();
- ele.parent().find('.area').remove();
- ele.after(cityhtml);
- var cityselect = ele.parent().find('.city');
- if(selected_cityid){ //设置默认的值选中,主要用于编辑的时候存在值,直接读取
- if(cityselect.find("option[value='"+selected_cityid+"']").length>0){
- cityselect.val(selected_cityid);
- cityselect.find('option:selected').change();
- }
- }
- });
- }
-
- });
- // 城市点击,地区更换
- $(document).on('change','.city',function(){
- var cityid = $(this).val();
- var ele = $(this);
- if(cityid){
- var areaurl = BASE_URL+'/Home/Ajax/area';
- var selected_areaid = $(this).attr('area-selected');
- $.post(areaurl,{cityid:cityid},function(data){
- var areahtml = '<select class="select area" style="margin-left:10px;" name="areaid">';
- $.each(data, function(i, value) {
- areahtml += '<option value="'+value.areaid+'">'+value.area+'</option>';
- });
- areahtml += '</select>';
- ele.parent().find('.area').remove();
- ele.after(areahtml);
- if(selected_areaid){ //设置默认的值选中,主要用于编辑的时候存在值,直接读取
- var areaselect = ele.parent().find('.area');
- if(areaselect.find("option[value='"+selected_areaid+"']").length>0){
- areaselect.val(selected_areaid);
- }
- }
- });
- }
- });
- });
- /* 上传图片预览弹出层 */
- //标签页切换(无下一步)
- function showTab() {
- $(".tab-nav li").click(function(){
- var self = $(this), target = self.data("tab");
- self.addClass("current").siblings(".current").removeClass("current");
- window.location.hash = "#" + target.substr(3);
- $(".tab-pane.in").removeClass("in");
- $("." + target).addClass("in");
- }).filter("[data-tab=tab" + window.location.hash.substr(1) + "]").click();
- }
- //标签页切换(有下一步)
- function nextTab() {
- $(".tab-nav li").click(function(){
- var self = $(this), target = self.data("tab");
- self.addClass("current").siblings(".current").removeClass("current");
- window.location.hash = "#" + target.substr(3);
- $(".tab-pane.in").removeClass("in");
- $("." + target).addClass("in");
- showBtn();
- }).filter("[data-tab=tab" + window.location.hash.substr(1) + "]").click();
- $("#submit-next").click(function(){
- $(".tab-nav li.current").next().click();
- showBtn();
- });
- }
- // 下一步按钮切换
- function showBtn() {
- var lastTabItem = $(".tab-nav li:last");
- if( lastTabItem.hasClass("current") ) {
- $("#submit").removeClass("hidden");
- $("#submit-next").addClass("hidden");
- } else {
- $("#submit").addClass("hidden");
- $("#submit-next").removeClass("hidden");
- }
- }
- //导航高亮
- function highlight_subnav(url){
- $('.side-sub-menu').find('a[href="'+url+'"]').closest('li').addClass('current');
- }
- //获取验证码
- function login(data,cb){
- $.ajax({
- type:"POST",
- cache: true,
- timeout: 5000,
- dataType: 'json',
- // jsonp: "jsoncallback",
- // url:"{:U('Code/getCode')}",
- url: '../../../Application/Home/LogReg/login2.php',
- contentType: "application/x-www-form-urlencoded; charset=UTF-8",
- data:data,
- success: cb,
- error: function(jqXHR, textStatus, errorThrown) {
- alert("发送验证码出错1:",jqXHR);
- // console.log("发送验证码出错:",jqXHR);
- },
- });
- }
- //手机、邮箱js验证
- function telMatch(tel){
- var patrn = /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
- if (!patrn.exec(tel)) {
- return false;
- }
- return true;
- }
- function emailMatch(email){
- var patrn = /(^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$)/;
- if (!patrn.exec(email)) {
- return false;
- }
- return true;
- }
|