标签:自动勾选checkboxlis 返回上一页网址 checkboxlist选中值验证 验证网址 验证正整数字
offline页面开发常用方法及页面控件验证,对一些CheckBoxList操作进行封装,新人可以直接使用该代码。
1、返回上一页网址
/// <summary>
/// Description:
/// 返回上一页网址
/// Author : 付义方
/// Create Date: 2014-02-09
/// </summary>
/// <returns>跳转Url</returns>
public string ToRedirect()
{ //没有来路地址
string RedirectUrl = "WebIndex.aspx";
if (Request.UrlReferrer != null)
{
//如果能获取来路地址
RedirectUrl = Request.UrlReferrer.ToString();
}
return RedirectUrl;
}2、根据字符串,自动勾选CheckBoxList对应项 /// <summary>
/// Description:
/// 根据字符串,自动勾选CheckBoxList对应项
/// Author : 付义方
/// Create Date: 2014-02-09
/// </summary>
/// <param name="str">字符串,格式要求为“A,B,C”</param>
/// <param name="checkBoxList">CheckBoxList控件</param>
public void FillCheckBoxList(string str, CheckBoxList checkBoxList)
{
string[] items = str.Split(‘,‘);
//遍历items
foreach (string item in items)
{
//如果值相等,则选中该项
foreach (ListItem listItem in checkBoxList.Items)
{
if (item == listItem.Value)
{
listItem.Selected = true;
}
else
{
continue;
}
}
}
}3、得到CheckBoxList选中值字符串
/// <summary>
/// Description:
/// 得到CheckBoxList值字符串
/// Author : 付义方
/// Create Date: 2014-02-09
/// </summary>
/// <returns>字符串,格式为“A,B,C”</returns>
public string GetChekVal(CheckBoxList _CheckBoxList)
{
string ChekVal = string.Empty;
for (int i = 0; i < _CheckBoxList.Items.Count; i++)
{
if (_CheckBoxList.Items[i].Selected == true)
{
ChekVal += _CheckBoxList.Items[i].Value + ",";
}
}
ChekVal = ChekVal.TrimEnd(‘,‘);
return ChekVal;
}4、Jquery CheckBoxList选中值验证 //验证CheckBoxList必选
var str = 0;
$("input[id^=<%=ChkToRangeList.ClientID %>]").each(function (i, val) {
if ($(i)[0].type == "checkbox") {
if ($(i)[0].checked) {
str += 1;
}
}
});
if (str == 0) {
alert("请选择显示设备!");
return false;
}
//验证RadioButtonList必选
var str = 0;
$("input[id^=<%=RdisFilterList.ClientID %>]").each(function (i, val) {
if ($(i)[0].type == "radio") {
if ($(i)[0].checked) {
str += 1;
}
}
});
if (str == 0) {
alert("请选是否过滤!");
return false;
} //验证网址
function checkUrl(url) {
var strRegex = new RegExp("((^http)|(^https)|(^ftp)):\/\/(\\w)+\.(\\w)+");
var re = new RegExp(strRegex);
if (re.exec(url)) {
return true;
} else {
return false;
}
}6、验证正整数字
//验证正整数字
function validateNumber(obj) {
var reg = /^\d+$/;
if (obj.length == 0) {
return true;
}
if (!reg.test(obj)) {
return false;
}
else {
return true;
}
}标签:自动勾选checkboxlis 返回上一页网址 checkboxlist选中值验证 验证网址 验证正整数字
原文地址:http://blog.csdn.net/fuyifang/article/details/45558689