JQuery平常用到的语法

//tr隐藏

<tr  id="trPassword"> </tr>
$("#trPassword").show();
$("#trPassword").hide();

//datagrid显示隐藏列

  $('#dg').datagrid('hideColumn', 'Password');
  $('#dg').datagrid('showColumn', 'Password');

//datagrid垂直、水平滚动条

  onLoadSuccess: function () {
    $("#dg").datagrid("resize", {  
         height: ($(window).height()),
         width:  ($(window).width())
     });  
}

//判断某个值在不在集合内,不存在这个集合内的结果为-1

//data[0].SPWorkType类型要与arr里面的类型相同 同为int 此验证只适用于int类型的验证
//parseInt字符串转int
var arr = [0, 1, 2, 3, 4, 5, 6, 9, 10];     
$.inArray(parseInt(data[0].SPWorkType), arr) 

//判断某个值包不包含某字符串,不存在结果为-1
//此大神还有其他的方法,转载借鉴
https://blog.csdn.net/xinghuo0007/article/details/70495460

var varD = "啦啦啦啦";
varD.indexOf("啦")

//将ID放入到IDS集合里

var ids = [];
for (var i = 0; i < row.length; i++) {
ids.push(row[i].ID);
}

//AJAX调用

 $.ajax({
     type: "post",
      url: '~/AuthorizedService.asmx/GetDetail',
      data: { ID: getParam("id") },
      dataType: "json",
      async: true,
      error: function (x, e) {
          return true;
      },
      success: function (data) {
          if (data.length > 0) {
              $("#txtAfterUserNo").textbox('setValue', data[0].AfterUserName);
              $("#txtBeginDate").val(data[0].AuthorBeginDateStr);
              $("#txtLastDate").val(data[0].AuthorEndDateStr);
          }
      }
  });

//datagrid列颜色

 {
  field: 'ResultOK', title: '结果最终', width: 150, styler: function (value, row, index) {
   if (row.ResultOK == "不合格")
        return 'background-color:red;';  
  else if(row.ResultOK == "合格")
       return 'background-color:green;';  
  }
}

//datagrid行颜色:设置background-color(背景色)为pink和文本颜色为blue;与columns、pageSize、onBeforeLoad等属性并列设置

 rowStyler:function(index,row){  
   if (row.listprice>50){    return 'background-color:pink;color:blue;font-weight:bold;';  }
}

datagrid加按钮:与columns、pageSize、onBeforeLoad等属性并列设置

 toolbar: [{
     text: '变更',
     iconCls: 'icon-edit',
     handler: function () { newData(); }
   }, '-', {
    text: '撤销变更',
    iconCls: 'icon-cancel',
    handler: function () { delRow(); }
   }],
   
 // 或者
  
  {
      field: "变更", title: "变更", align: "center", width: 50, formatter: function (value, row, index) {
      var a = "";
      if (row.State == null) {
          a = "href='#'  onclick='newData(" + row.Id + ",\"Add\")' ";
      else {
          a = "style='color:#B0C4DE'";
      }
        return "<a  " + a + "  target='_self'>变更</a>";
   }
 }

formatter方法里加入Ajax:根据ID查找中文名称

 {
        field: 'CheckItemName', title: '扫描项', width: 300, formatter: function (value, row, index) {
          var vCheckItem = "";
          var htmlObj = $.ajax({
                url: '<%=ResolveUrl("../_CCheckItem/CCheckItemDataService.asmx/GetCheckItemName")%>',
                data: { ids: row.CheckItemIds },
                type: "post",
                async: false
             });
           var text = htmlObj.responseText;
           var json = JSON.parse(text);
           $(json.rows).each(function (index, value) {
              vCheckItem=(index == 0)?value.CheckItem:vCheckItem+','+value.CheckItem;
           });
            return vCheckItem;
    }
 },

后台方法
 /// <summary>
 /// 获取检查项
 /// </summary>
 /// <param name="CheckItemIDs"></param>
 /// <returns></returns>
[WebMethod]
public void GetCheckItemName()
{
    string ids = Context.Request["ids"].Trim();//
    JsonModelInfoList<JsonCheckItemInfo> datasource = bll.GetCheckItemName(ids);
    string json = JsonConvert.SerializeObject(datasource);
    Context.Response.ContentType = "json";
    Context.Response.Write(json);
 }
 
 /// <summary>
/// 获取检查项
/// </summary>
/// <param name="CheckItemIDs"></param>
/// <returns></returns>
public JsonModelInfoList<JsonCheckItemInfo> GetCheckItemName(string CheckItemIDs)
{
   string sql = @"select a.* from CheckItemInfo a where 1=1 and ID in ("+ CheckItemIDs + ")";
   List<JsonCheckItemInfo> rows = DapperHelper.Select<JsonCheckItemInfo>(TargetDB.Target, sql, null);
   // 总数
   int total = rows.Count;
   List<JsonCheckItemInfo> temp = rows;
   return new JsonModelInfoList<JsonCheckItemInfo> { total = total, rows = rows };
 }
/// <summary>
/// 模型列表(For DataGrid)
/// </summary>
 /// <typeparam name="T"></typeparam>
 [Serializable]
 public class JsonModelInfoList<T>
 {
    /// <summary>
    /// 总数
    /// </summary>
    public int total;
    /// <summary>
    /// 用户项
   /// </summary>
  public List<T> rows;
   /// <summary>
   /// 构造函数
   /// </summary>
   public JsonModelInfoList()
   {
       rows = new List<T>();
    }
 }

//绑定easyui-combotree及combobox设置不可用

<label>角色:</label><input id="cmbRoleName" class="easyui-combotree"     style="width: 150px;" />
 $(function () {
   $("#cmbRoleName").combobox({
      method:'post',
      url: '<%=ResolveUrl("~/BaseDataService.asmx/GetRoleName")%>',
      valueField: 'ID',
      textField: 'RoleName'
})

$('#ddlSpec').combobox({ disabled: true });
   

//给li标签添加click事件

var vli = $("<li></li>")//把<li> 用$()括起来,形成一个jquery变量
vli.bind('click',function(){
  alert('OK';)
})
或者 nameLi为li的class名称,将此代码放入到  $(function () {  });里面
$(document).bind('click', '.nameLi', function (e) {
    $(e.target).closest("li").css("color","red"); //遍历li将选中的li文字变红色
    alert('OK';)
 });

//弹出新页面

  public static void open(Page p, string url, string width, string Height)
  {
      p.ClientScript.RegisterStartupScript(p.GetType(), "", "window.open('" + url + "','_blank','width:" + width + ",height:" + Height + ",menubar=no,toolbar=yes,resizable=yes,toolbar=no, status=no,scrollbars=yes')", true);
  }
 //调用
 string param = HttpUtility.UrlEncode(newfile.FullName)+","+ HttpUtility.UrlEncode(imgFullPath);
 OperateMessage.open(Page, "NameListImg.aspx?param=" + param + "", "100%", "100%"); 

//跳转页面

Response.Redirect("NameListImg.aspx?param=" + param);

//window.open介绍

1.语法  window.open(pageURL,name,parameters)
2.参数
其中yes/no也可使用1/0;pixel value为具体的数值,单位象素。参数 | 取值范围 | 说明alwaysLowered | yes/no | 指定窗口隐藏在所有窗口之后 
alwaysRaised | yes/no | 指定窗口悬浮在所有窗口之上 
depended | yes/no | 是否和父窗口同时关闭 
directories | yes/no | Nav2和3的目录栏是否可见 
height | pixel value | 窗口高度 
hotkeys | yes/no | 在没菜单栏的窗口中设安全退出热键 
innerHeight | pixel value | 窗口中文档的像素高度 
innerWidth | pixel value | 窗口中文档的像素宽度 
location | yes/no | 位置栏是否可见 
menubar | yes/no | 菜单栏是否可见 
outerHeight | pixel value | 设定窗口(包括装饰边框)的像素高度 
outerWidth | pixel value | 设定窗口(包括装饰边框)的像素宽度 
resizable | yes/no | 窗口大小是否可调整 
screenX | pixel value | 窗口距屏幕左边界的像素长度 
screenY | pixel value | 窗口距屏幕上边界的像素长度 
scrollbars | yes/no | 窗口是否可有滚动栏 
titlebar | yes/no | 窗口题目栏是否可见 
toolbar | yes/no | 窗口工具栏是否可见 
Width | pixel value | 窗口的像素宽度 
z-look | yes/no | 窗口被激活后是否浮在其它窗口之上

//弹出子窗口

 父窗口--页面
<div id="dataForm" title="Window" style="overflow: hidden;">
   <iframe id="winSrc" frameborder="0" width="100%" height="100%" name="selfFrame"></iframe>
 </div>   
 父窗口--方法
 openWin('详情', "DetailInfo.aspx?ID=" + intID, 600, 350);
 .JS:
 var win;
 function openWin(title, url, width, height,left,top) {
    win=$('#dataForm').window({
      title: 'Window',        
      closed: true,
      minimizable: false,
      style: { position: 'fixed' },
      onClose: function () { document.getElementById("winSrc").src = ""; },
      modal: true
  });
 $('#dataForm').window("open");
 var opt = {}
 opt.width = $(window).width() - 150;
 opt.height = $(window).height() - 150;
 if (width) { opt.width = width;}
 if (height ) { opt.height = height ;}
 $('#dataForm').window('resize', opt);
 $('#dataForm').window('setTitle', title);$
 $('#dataForm').window('move', {
    left: left==undefined?240:left,
    top: top == undefined ? 30 : top
 });
 document.getElementById("winSrc").src = url;      
}

//关闭子窗口时刷新父窗口

function reflush(tab) {    
    tab.datagrid("clearSelections");
    tab.datagrid("reload");
    //下面为刷新treegrid
    //tab.treegrid("unselectAll");
    //tab.treegrid("reload");
}
子窗口调用
reflush(parent.tab);或者直接parent.reflush();
父窗口
var tab=$('#dg').datagrid({  //生成grid代码   });

//子窗口自动关闭–子窗口调用

function goCancel() {
   parent.win.window("close");
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值