jquery之杂记

  //选中事件,放在初始化方法里面,toolbar下面

onSelect : function(rowIndex, rowData) {
                            queryChannelFloor(rowIndex, rowData);
                        }

//图片展示

                   {
                            field : 'adImg',
                            title : '广告图片',
                            width : 200,
                            sortable : true,
                            align : 'center',
                            formatter:function(value){
                                return "<img src='"+value+"' width='60px' height='30px' />";
                            }
                        }

//图片操作

    $("#addAdImg").val("");

$("#addAdImg").val(data.adImg);

//初始化时间

var appPath = getAppPath();
$(function(){
    var d = new Date();
    var vYear = d.getFullYear();
    var vMon = d.getMonth() + 1;
    var vDay = d.getDate() - 1;
    var date = vYear+"-"+vMon+"-"+vDay;
    $('#searchTime').datebox("setValue",date);
    $('#searchTimeEd').datebox("setValue",date);
    logGrid();
});

function logGrid(){
    $('#queryLogGrid').datagrid({
        url:appPath+'/page/portalSearchLog/logList',
        method:'post',
        queryParams:getQueryParam(),

//或者是

    $("#bgCommitTime").datebox("setValue", getTimeString()+" 00:00:00");
    $("#endCommitTime").datebox("setValue", getTimeString()+" 23:59:59");

/**
 * 初始化时间
 * @returns {String}
 */
function getTimeString(){
    var day = new Date();
    var Year = 0;
    var Month = 0;
    var Day = 0;
    var CurrentDate = "";
    Year = day.getFullYear();
    Month = day.getMonth() + 1;
    Day = day.getDate();

    CurrentDate += Year + "-";

    if (Month >= 10) {
        CurrentDate += Month + "-";
    } else {
        CurrentDate += "0" + Month + "-";
    }
    if (Day >= 10) {
        CurrentDate += Day;
    } else {
        CurrentDate += "0" + Day;
    }

    return CurrentDate;
}
//特殊编辑器的使用,首先要引入<script src="${ctx }/js/lib/ckeditor/ckeditor.js"></script>这个文件

        <tr>
              <td class="queryTitle" width="80px">分类代码</td>
              <td class="queryContent" colspan="3"><textarea id="headCode" class="ckeditor"></textarea></td>
          </tr>

//赋予空值(初始化)

CKEDITOR.instances.headCode.setData('');

//编辑展示

CKEDITOR.instances.headCode.setData(data.headCode);

//取值

ecChannelPage.headCode = CKEDITOR.instances.headCode.getData();

if(seoWordName==""){$("#seoWordNameFont").html("seoWord名称不能为空!");return;}else{$("#seoWordNameFont").html("*");}

        <td class="queryTitle" width="100">SeoWord名称</td>
                <td class="queryContent" width="100">
                      <input type="text" id="addseoWordName" name="addseoWordName"/>
                           <font id="seoWordNameFont" color="red">*</font>
          </td>

   <td class="queryTitle" width="100">SeoWordUrl</td>
        <td class="queryContent" width="100">
             <input type="text" id="addseoWordUrl" name="addseoWordUrl"/>
               <font id="seoWordUrlFont" color="gray">格式:http://www.***.com</font>
   </td>

    var seoWordUrl=$.trim($("#addseoWordUrl").val());

  var strRegex = "^http://(([a-zA-z0-9]|-){1,}\\.){1,}[a-zA-z0-9]{1,}-*" ;
    var re=new RegExp(strRegex);
    if (!re.test(seoWordUrl) && seoWordUrl.length>0){
       $("#seoWordUrlFont").css('color','red');
       $("#seoWordUrlFont").html("URL格式不正确");return;
    }
    else{
       $("#seoWordUrlFont").css('color','gray');
       $("#seoWordUrlFont").html("格式:http://www.***.com");
    }

//限数字

    var numC=/^\d+$/;
    if(!numC.test(priority) && priority.length>0){$('#priorityFont').css('color','red');return;}else{$('#priorityFont').css('color','gray');}

//checkbox
  //选中事件,放在初始化方法里面,toolbar下面

onSelect : function(rowIndex, rowData) {
                            queryChannelFloor(rowIndex, rowData);
                        }

//图片展示

                   {
                            field : 'adImg',
                            title : '广告图片',
                            width : 200,
                            sortable : true,
                            align : 'center',
                            formatter:function(value){
                                return "<img src='"+value+"' width='60px' height='30px' />";
                            }
                        }

//图片操作

    $("#addAdImg").val("");

$("#addAdImg").val(data.adImg);

//初始化时间

var appPath = getAppPath();
$(function(){
    var d = new Date();
    var vYear = d.getFullYear();
    var vMon = d.getMonth() + 1;
    var vDay = d.getDate() - 1;
    var date = vYear+"-"+vMon+"-"+vDay;
    $('#searchTime').datebox("setValue",date);
    $('#searchTimeEd').datebox("setValue",date);
    logGrid();
});

function logGrid(){
    $('#queryLogGrid').datagrid({
        url:appPath+'/page/portalSearchLog/logList',
        method:'post',
        queryParams:getQueryParam(),

//或者是

    $("#bgCommitTime").datebox("setValue", getTimeString()+" 00:00:00");
    $("#endCommitTime").datebox("setValue", getTimeString()+" 23:59:59");

/**
 * 初始化时间
 * @returns {String}
 */
function getTimeString(){
    var day = new Date();
    var Year = 0;
    var Month = 0;
    var Day = 0;
    var CurrentDate = "";
    Year = day.getFullYear();
    Month = day.getMonth() + 1;
    Day = day.getDate();

    CurrentDate += Year + "-";

    if (Month >= 10) {
        CurrentDate += Month + "-";
    } else {
        CurrentDate += "0" + Month + "-";
    }
    if (Day >= 10) {
        CurrentDate += Day;
    } else {
        CurrentDate += "0" + Day;
    }

    return CurrentDate;
}
//特殊编辑器的使用,首先要引入<script src="${ctx }/js/lib/ckeditor/ckeditor.js"></script>这个文件

        <tr>
              <td class="queryTitle" width="80px">分类代码</td>
              <td class="queryContent" colspan="3"><textarea id="headCode" class="ckeditor"></textarea></td>
          </tr>

//赋予空值(初始化)

CKEDITOR.instances.headCode.setData('');

//编辑展示

CKEDITOR.instances.headCode.setData(data.headCode);

//取值

ecChannelPage.headCode = CKEDITOR.instances.headCode.getData();

if(seoWordName==""){$("#seoWordNameFont").html("seoWord名称不能为空!");return;}else{$("#seoWordNameFont").html("*");}

        <td class="queryTitle" width="100">SeoWord名称</td>
                <td class="queryContent" width="100">
                      <input type="text" id="addseoWordName" name="addseoWordName"/>
                           <font id="seoWordNameFont" color="red">*</font>
          </td>

   <td class="queryTitle" width="100">SeoWordUrl</td>
        <td class="queryContent" width="100">
             <input type="text" id="addseoWordUrl" name="addseoWordUrl"/>
               <font id="seoWordUrlFont" color="gray">格式:http://www.***.com</font>
   </td>

    var seoWordUrl=$.trim($("#addseoWordUrl").val());

  var strRegex = "^http://(([a-zA-z0-9]|-){1,}\\.){1,}[a-zA-z0-9]{1,}-*" ;
    var re=new RegExp(strRegex);
    if (!re.test(seoWordUrl) && seoWordUrl.length>0){
       $("#seoWordUrlFont").css('color','red');
       $("#seoWordUrlFont").html("URL格式不正确");return;
    }
    else{
       $("#seoWordUrlFont").css('color','gray');
       $("#seoWordUrlFont").html("格式:http://www.***.com");
    }

//限数字

    var numC=/^\d+$/;
    if(!numC.test(priority) && priority.length>0){$('#priorityFont').css('color','red');return;}else{$('#priorityFont').css('color','gray');}

//checkbox
/**
     * @description 去往商品维护
     */
    @RequestMapping(value="/gotoExpand")
    public String gotoExpand(HttpServletRequest request)
    {
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        for (ProductShowField p : ProductShowField.values()) {
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("name", p.name());
            map.put("code", p.getCode());
//            System.out.println(p.name()); //得到枚举的名字
//            System.out.println(p.getCode()); //得到枚举的code
            list.add(map);
        }
        request.setAttribute("productShowFieldList", list);
        return "/jsp/seo/productExpand.jsp";
    }
var productShowField = document.getElementsByName("productShowField");
    for ( var i = 0; i < productShowField.length; i++) {
        if(productShowField[i].checked){
            productExpand.showfield += productShowField[i].value + ',';
        }
    }
    if(productExpand.showfield!=null&&productExpand.showfield!=''){
        productExpand.showfield = productExpand.showfield.substring(0, productExpand.showfield.length-1);
    }

//checkbox 初始化

    $("#productIdPHidden").val(productIdP);
    $("#canHdfk").attr("selected","selected");
    var title="添加信息";
    var iconC="icon-add";
    var productShowField = document.getElementsByName("productShowField");
    for ( var i = 0; i < productShowField.length; i++) {
        productShowField[i].checked = false;
    }

    if(data.showfield!=null&&data.showfield!=''){
                    var showField = data.showfield.split(",");
                    for ( var i = 0; i < productShowField.length; i++) {
                        for ( var j = 0; j < showField.length; j++) {
                            if(showField[j] == productShowField[i].value){
                                productShowField[i].checked = true;
                            }
                        }
                    }
                }
//枚举

/**
 * 商品显示字段
 *
 */
public enum ProductShowField {
    pCode("商品编码"),
    referPrice("参考价"),
    pEvaluationn("商品评价"),
    pSpecif("规格"),
    paymentType("支付方式"),
    j1Service("健一服务");

private String i;

    private ProductShowField(String n){
        this.i = n;
    }

    public String getCode(){
        return this.i;
    }

    public static NAdNo resolve(String i){
        try {
            return NAdNo.valueOf(i);
        } catch (Exception e) {
            return null;
        }
    }

    public static String getNoName(String no){
         try {
            return NAdNo.resolve(no).getCode();
        } catch (Exception e) {
            return "";
        }
    }
}
//微信

  @RequestMapping(value = "/toPageWeixin")

  public String toPageWeixin(HttpServletRequest request) {
      request.setAttribute("weixinStatusList", NWeixinStatus.values());

      return "/jsp/weixin/weixinActivity.jsp";
  }
<td class="queryTitle" width="80px">活动状态</td>
       <td class="queryContent">
            <select class="inputText easyui-combobox" id="isStatus"  style="width: 150px" panelHeight="auto">
                <option value="">请选择</option>
                <c:forEach var="weixinStatus" items="${weixinStatusList }">
                    <option value="${weixinStatus }">${weixinStatus.code }</option>
                </c:forEach>
            </select>
        </td>

 <!-- 查询 -->
<table class="queryTable">
    <tr>
        <td class="queryContent"><input class="inputText  searchText"      type="text" id="queryParam"    placeholder="商品编号/商品名称/工号/用户名"/></td>
        <td class="queryBtnTd"><a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search"   onclick="doQuery()">查&nbsp;&nbsp;询</a></td>
    </tr>
</table>

//js

function chooseRadio(n)
{
    $("input:radio[name='addcategory']").eq(n).attr("checked",'checked');
    if(n==0)
    {
       $("#productSpan").css("display","none");
       $("#catalogSpan").css("display","block");
    }else{
       $("#productSpan").css("display","block");
       $("#catalogSpan").css("display","none");
    }
}

//jsp

<tr>
                        <td class="queryTitle" width="100">类别</td>
                        <td class="queryContent" >
                            <input checked="checked" name="addcategory" type="radio" value="catalog" onclick="chooseRadio(0)" />类目<input name="addcategory" type="radio" value="product" onclick="chooseRadio(1)" />商品
                        </td>
                        <td class="queryContent" colspan="2">
                            <span id="productSpan" style="display:none;">商品编码<input type="text" id="addproductCode" name="addproductCode" /></span>
                            <span id="catalogSpan" >类目ID<input type="text" id="addcatalogId" name="addcatalogId" /></span>
                            <font id="categoryFont" color="grey">商品编码或者类目ID不允许出现重复记录</font>
                        </td>
                    </tr>   

var category=$("input[name='addcategory']:checked").val();//类别

if(category=="catalog")
    {
        if(catalogId==null || catalogId.length==0){$("#categoryFont").html("类目ID不能为空");$("#categoryFont").css("color","red");return;}
    }else{
        if(productCode==null || productCode.length==0){$("#categoryFont").html("商品编码不能为空");$("#categoryFont").css("color","red");return;}
    }

//排序

{
                                    field : 'orderNum',
                                    title : '排序',
                                    width : 100,
                                    align : 'center',
                                    sortable : true,
                                    formatter:function(value,rowData,rowIndex){
                                         var obj=JSON.stringify(rowData);
                                          return "<input type='text' id='orderNum"+rowIndex+"' style='width: 76px;'  value='"+value+"' onchange='onblus(this,"+obj+")'/>";
                                   }
                                },

//填写顺序 后实时保存
function onblus (obj,data){
   var orderNum = $(obj).attr("value");
  if(orderNum==null || orderNum==''){
      $(obj).attr("value",data.orderNum);
      return;
  }
  var flag2=validateNum(orderNum);
    if(!flag2){
        $.messager.alert('提示信息','排序请填写正确的0~99之间的自然数','info',function(){
            $(obj).attr("value",data.orderNum);
            $(obj).focus();
        });
        return;
    }

    var pageIndexImg = new Object();
    pageIndexImg.orderNum=orderNum;
    pageIndexImg.imageType=Number($("#imgType").val());
    pageIndexImg.id=data.id;
   doAjax({
        url : appPath + '/page/pageIndexMrgAct/update',
        type : 'post',
        data : pageIndexImg,
        success : function(data) {
            if (data.code != 0) {
                $.messager.alert('提示信息', data.msg + ',操作失败', 'error');
            }
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            $.messager.alert('提示信息', '排序保存失败' + textStatus, 'error');
        }
    });

}
/**
     * 根据Id更新图片信息
     *
     * @param request
     * @param response
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Map<String,Object> updateOrderNum(HttpServletRequest request,
            HttpServletResponse response,PageIndexImg pageIndexImg) {
        Map<String,Object> mapRes=new HashMap<String,Object>();
        String userId = request.getSession().getAttribute("userId").toString();
        try{
            if (pageIndexImg==null || pageIndexImg.getId()==null) {
                mapRes.put("code", -1);
                mapRes.put("msg", "参数不全");
                return mapRes;
            }
            pageIndexImg.setEditTime(StringUtil.returnDateFormat(new Date(),
                    "yyyy-MM-dd HH:mm:ss"));
            pageIndexImg.setEditUserId(Integer.parseInt(userId));
            ServiceMessage<?> res=pageIndexImgService.update(pageIndexImg);
            if(res.getStatus().getCode().equals("0")){
                mapRes.put("code", 0);
                mapRes.put("msg", "ok");
            }else{
                mapRes.put("code", -1);
                mapRes.put("msg",res.getMessage());
            }
        }catch(Exception e){
            mapRes.put("code", -1);
            mapRes.put("msg", "处理异常");
            logger.error(e.getMessage());
        }
        return mapRes;
    }

===============================================


//鼠标事件

{
                                        field : 'imageUrl',
                                        title : '图片',
                                        width : 80,
                                        align : 'center',
                                        sortable : false,
                                        formatter : function(value, rowData,
                                                rowIndex) {
                                            if (value == null || value == '') {
                                                return "<img  border='0' src='"
                                                        + appPath
                                                        + "/js/lib/jquery-easyui/themes/icons/blank.gif"
                                                        + "' />";
                                            } else {
                                                return "<img title='显示图片'  onMousemove=\"mouseOn(event)\"  onmouseout='mouseOff()' rel='"
                                                        + rowData.imageUrl
                                                        + "' src='"
                                                        + appPath
                                                        + "/js/lib/jquery-easyui/themes/icons/search.png"
                                                        + "' />";
                                            }
                                        }
                                    },

// 图片显示,鼠标移入事件
function mouseOn(e) {
    if ($("#showImgDetail").not(":visible")) {
        var dom = e.srcElement || e.target;
        var tp = $(dom).offset().top;
        var lf = $(dom).offset().left + $(dom).width() + 10;
        $("#showImgDetail").attr("src", $(dom).attr("rel"));
        $("#showImgDetail").css("top", tp);
        $("#showImgDetail").css("left", lf);
        $("#showImgDetail").show();
    }
}

// 图片显示,鼠标移出事件
function mouseOff() {
    $("#showImgDetail").hide();
}

<img id="showImgDetail"
    style="position: absolute; display: none; border: 1px #EEEEFF solid;"
    alt="" src="" />

//关闭窗口之废话连篇

function closeWin(id) {
    if(id='addDlg'){
        if($("#addUrl").val()=='' && $("#addKeywords1").val()==''
            && $("#addLinkUrl1").val()==''){
            $('#'+id).window('close');
        }else{
            $.messager.defaults = { ok: "是", cancel: "否,继续填写" };
            $.messager.confirm('提示信息','将丢失已经填写的内容,是否继续关闭?',function(r){
                if(r){
                    $('#'+id).window('close');
                }
            });
        }
    }else{
        $('#'+id).window('close');
    }
}
上一篇:13 款惊艳的 Node.js 框架——第1部分


下一篇:oracle中anyData数据类型的使用实例