判断单选框是否被选择
$(".ip_check").each(function (index, li) {
if ($(li).is(":checked")) {
newID=$(li).parent(".stark_check").attr("id")
}
})
js调整日期格式
function getNowFormatDate() {
var date = new Date();
var seperator1 = "/";
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = year + seperator1 + month + seperator1 + strDate;
return currentdate;
}
js小数相加出现精度不准确的问题
number类型的数字使用toFixed(2)在进行加减操作:2表示小数点后面保留两外
countMoney = (parseFloat(countMoney) + parseFloat($(this).parents(".parents").attr("oid"))).toFixed(2)
js日期时间比较
function conpareTime(yourtime) {
var date = new Date();
var seperator1 = "-";
var nowyear = date.getFullYear();
var nowmonth = date.getMonth() + 1;
var nowday = date.getDate();
var currentdate = nowyear + seperator1 + nowmonth + seperator1 + nowday;
yourtime = yourtime.replace(/-/g, "/");//替换字符,变成标准格式
currentdate = currentdate.replace(/-/g, "/")
var d2 = new Date(Date.parse(currentdate));//取今天的日期
var d1 = new Date(Date.parse(yourtime));
console.log(d2)
console.log(d1)
if (d1 < d2) {
bantime = -1
} else {
bantime = 1;
}
}
c#时间比较
时间字符串转换成时间格式然后进行比较
string oDataFormet = context.Request.Form["oDataFormet"];
string bantimg = DateTime.Now.ToString("yyyy-MM-dd");
DateTime oBantimg = Convert.ToDateTime(bantimg);
DateTime ooDataFormet = Convert.ToDateTime(oDataFormet);
int compNum = DateTime.Compare(oBantimg, ooDataFormet);
js cookie的使用
详细使用方法
// 设置cookie
function addCookie(name, value, days, path) { /**添加设置cookie**/
// //var name = escape(name);
// //var value = escape(value);
// var expires = new Date();
// expires.setTime(expires.getTime() + days * 3600000 * 24);
// //path=/,表示cookie能在整个网站下使用,path=/temp,表示cookie只能在temp目录下使用
// path = path == "" ? "" : "; path=" + path;
// //GMT(Greenwich Mean Time)是格林尼治平时,现在的标准时间,协调世界时是UTC
// //参数days只能是数字型
//var _expires = (typeof days) == "string" ? "" : "; expires=" + expires.toUTCString();
//document.cookie = decodeURIComponent(name + "=" + value + _expires + path);
$.cookie(name, value, { expires: days, path: path });
}
//获取cookie
//获取保存在cookie中的用户信息
function getCookieValue(name) { /**获取cookie的值,根据cookie的键获取值**/
//用处理字符串的方式查找到key对应value
var name = escape(name);
//读cookie属性,这将返回文档的所有cookie
var allcookies = document.cookie;
//查找名为name的cookie的开始位置
name += "=";
var pos = allcookies.indexOf(name);
//如果找到了具有该名字的cookie,那么提取并使用它的值
if (pos != -1) { //如果pos值为-1则说明搜索"version="失败
var start = pos + name.length; //cookie值开始的位置
var end = allcookies.indexOf(";", start); //从cookie值开始的位置起搜索第一个";"的位置,即cookie值结尾的位置
if (end == -1) end = allcookies.length; //如果end值为-1说明cookie列表里只有一个cookie
var value = allcookies.substring(start, end); //提取cookie的值
return (value); //对它解码
} else { //搜索失败,返回空字符串
return "";
}
}
//清除cookie
$.cookie('keytwo', null)
C# 生成二维码使用
all_QR.Append("<img src=data:image/png;base64,"+QRCodeUtil.Encode(""+oOrder_number+"").ImageToBytes().BinaryToBase64()+" />");
C# 保留两位小数
Convert.ToDecimal(lbdt.Rows[i]["Total_OfflineMoney"]).ToString("N")
js 点击事件的嵌套
//外面的点击事件
$("#A").click(function(){
alert(0);
//执行B的点击事件之前解除A的绑定
$("#b").unbind('click').click(function () {
alert(1)
})
})
js键盘按下事件绑定
//绑定的节点
$(document).keydown(function (event) {
if (event.keyCode == 90) {
}
});
C#DataTable 类型换成list
将数据库读取的数据转换成list范型
private List<M_Sys_AppMenu> GetModelList(DataTable dt)
{
List<M_Sys_AppMenu> list = new List<M_Sys_AppMenu>();
if (dt != null)
{
foreach (DataRow dr in dt.Rows)
{
list.Add(GetModel(dr));
}
}
return list;
}
C#拆一个简单的mvc+EF架构
mvc+EF架构
JS顶部标题栏
<nav class="navbar navbar-default navbar-fixed-top navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Logo</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">安卓</a></li>
<li><a href="#">苹果</a></li>
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Windows
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Windows7</a></li>
<li><a href="#">Windows8.1</a></li>
<li><a href="#">Windows10</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right">
<div class="input-group">
<span class="input-group-addon">@</span>
<input list="lst" type="text" class="form-control" placeholder="Search" />
<datalist id="lst">
<option value="IE"></option>
<option value="Firefox"></option>
<option value="chrome"></option>
<option value="safari"></option>
</datalist>
</div>
<button class="btn btn-success" type="submit">search</button>
</form>
</div>
</nav>
C# 后台解析json,简单方法 字符串序列化为对象,取值
https://www.cnblogs.com/aashui/p/9486091.html
C# DataTable数据序列化
//序列化
public static string SerializeDataTable(DataTable dt)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
foreach (DataRow dr in dt.Rows)//每一行信息,新建一个Dictionary<string,object>,将该行的每列信息加入到字典
{
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (DataColumn dc in dt.Columns)
{
result.Add(dc.ColumnName, dr[dc].ToString());
}
list.Add(result);
}
return serializer.Serialize(list);//调用Serializer方法
}
/// <summary>
/// DataTable反序列化
/// </summary>
/// <param name="strJson"></param>
/// <returns></returns>
public static DataTable DeserializerTable(string strJson)
{
DataTable dt = new DataTable();
JavaScriptSerializer serializer = new JavaScriptSerializer();
ArrayList arralList = serializer.Deserialize<ArrayList>(strJson);//反序列化ArrayList类型
if (arralList.Count > 0)//反序列化后ArrayList个数不为0
{
foreach (Dictionary<string, object> row in arralList)
{
if (dt.Columns.Count == 0)//新建的DataTable中无任何信息,为其添加列名及类型
{
foreach (string key in row.Keys)
{
dt.Columns.Add(key, row[key].GetType());//添加dt的列名
}
}
DataRow dr = dt.NewRow();
foreach (string key in row.Keys)//讲arrayList中的值添加到DataTable中
{
dr[key] = row[key];//添加列值
}
dt.Rows.Add(dr);//添加一行
}
}
return dt;
}
JQuery $.post() 方法使用 HTTP POST 请求从服务器加载数据
$.post(
'iconsdata_test.aspx',
{
txtkey: $('#txtkey').val()
},
function (data) //回传函数
{
if (data == "") {
} else {
document.getElementById('content_html').innerHTML = data;
}
}
);
**store.js - 轻松实现本地存储(LocalStorage) **
store.js 是一个兼容所有浏览器的 LocalStorage 包装器,不需要Flashokie
或者 Flash 。store.js 会根据浏览器自动选择使用 localStorage、globalStorage 或者 userData 来实现本地存储功能 。
store.js 提供非常简洁的 API 来实现跨浏览器的本地存储功能:
复制代码 代码如下:
//存储键值对key-value
store.set('username', 'LCQ')
//根据key,获取存储的value值
store.get('username')
//移除指定的key数据
store.remove('username')
//清除所有key
store.clear()
//运用store.js存储轻量级的json对象
store.set('user', { name: 'lcq' })
//根据key,获取一个存储对象
var user = store.get('user')
console.log(user.name);
**JS layer.open模型弹出层 **
layer.open({
type: 2, //类型,解析url
closeBtn: 1, //关闭按钮是否显示 1显示0不显
maxmin:true,//最大最小化 默认false
title: title, //页面标题
shadeClose: true, //点击遮罩区域是否关闭页面
shade: 0.8, //遮罩透明度
area: ['900px', '500px'], //弹出层页面比例
content: '${ctx}/manage/classPlan/courseList?isOnline='+type //弹出层的url
yes:function(index,layero){ //该回调携带两个参数,分别为当前层索引、当前层DOM对象
layer.close(index); //如果设定了yes回调,需进行手工关闭
}
});
**JS $.layerSetup弹出框 **
$.layerSetup({
//id框架打开的id
id: "sentence_insertpic",
title: '',
top: 800,
content: '<iframe id="frm_getcontentpic" src="/piclist/Testgetcontentpic.aspx" frameborder="0" height="560" width="780" ></iframe>',
isbg: false,
templete: '<div class="showwint_mini_title_edit"><span class="showwint_mini_close_btn_edit"><a href="javascript:void(null);" class="layerclose"></a></span><span class="showwint_mini_title_content_edit" id="@moveid@"><span id="@titleid@"></span><a id="d_top_menu_edit" class="d_top_menu_cur" href="javascript:void(0);" target="_self">选择题头图</a></span></div><div class="showwint_mini_content_edit"><div class="showwint_mini_content_content_edit" id="@contentid@"></div></div>'
});
$.layershow();
//代码解释
/* <div class="showwint_mini_title_edit">
<span class="showwint_mini_close_btn_edit">
//关闭按钮
<a href="javascript:void(null);"class="layerclose"></a>
</span>
//下面是固定样式
<span class="showwint_mini_title_content_edit" id="@moveid@">
//下面是固定样式
<span id="@titleid@"></span>
//框架标题
<a id="d_top_menu_edit" class="d_top_menu_cur" href="javascript:void(0);" target="_self">选择题头图</a>
</span>
</div>
<div class="showwint_mini_content_edit">
//打开的窗口显示的位置 下面是固定样式
<div class="showwint_mini_content_content_edit" id="@contentid@"></div>
</div>
*/
**JS Ajax请求中cache属性 **
cache作用:是否在缓存中读取数据的读取。
cache属性是true(默认值)时:在第一次请求完成之后,如果地址和参数不变化,第二次去请求,会默认获取缓存中的数据,不去读取服务器端的最新数据。
cache属性是flase(默认值)时:每次读取的是最新的数据。
ajax缓存只对GET方式的请求有效,因为浏览器认为POST请求提交的内容必定有变化,所以不走缓存。
**JS 字符限制提示 **
jQuery(document).ready(function () {
//精简标题
jQuery("#videoTitle").textlimit("#span", 22);
})
jQuery.fn.textlimit = function (counter_el, thelimit, speed) {
var charDelSpeed = speed || 15;
var toggleCharDel = speed != -1;
var toggleTrim = true;
var that = this[0];
var isCtrl = false;
updateCounter();
function updateCounter() {
if (typeof that == "object")
var str = that.value;
var valueLength = 0;
for (var i = 0; i < str.length; i++) {
var c = str.charCodeAt(i);
//根据单双字节进行长度计算,单字节+1
if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
valueLength += 1;
} else {
valueLength += 2;
}
}
valueLength = (valueLength / 2).toFixed(0);
//jQuery(counter_el).text(thelimit - that.value.length + "个字符");
var a = thelimit - valueLength;
if (a < 0) {
jQuery(counter_el).text("还可以输入0个字符");
} else {
jQuery(counter_el).text("还可以输入" + a + "个字");
}
};
this.keydown(function (e) {
if (e.which == 17) isCtrl = true;
var ctrl_a = (e.which == 65 && isCtrl == true) ? true : false; // detect and allow CTRL + A selects all.
var ctrl_v = (e.which == 86 && isCtrl == true) ? true : false; // detect and allow CTRL + V paste.
// 8 is 'backspace' and 46 is 'delete'
var c = that.value;;
if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
c = 0.5;
} else {
c = 1;
}
if (c >= thelimit && e.which != '8' && e.which != '46' && ctrl_a == false && ctrl_v == false)
e.preventDefault();
})
.keyup(function (e) {
updateCounter();
if (e.which == 17)
isCtrl = false;
if (this.value.length >= thelimit && toggleTrim) {
if (toggleCharDel) {
// first, trim the text a bit so the char trimming won't take forever
// Also check if there are more than 10 extra chars, then trim. just in case.
if ((this.value.length - thelimit) > 10)
that.value = that.value.substr(0, thelimit + 100);
var init = setInterval
(
function () {
if (that.value.length <= 54) {
init = clearInterval(init); updateCounter()
}
else {
// deleting extra chars (one by one)
that.value = that.value.substring(0, that.value.length - 1); jQuery(counter_el).text('Trimming... ' + (thelimit - that.value.length));
}
}, charDelSpeed
);
}
else this.value = that.value.substr(0, thelimit);
}
});
};
//超出后可以监听键盘按下 οnkeyup="textCounter(this.form.videoTitle,44);"
function textCounter(field, maxlimit) {
var str = "";
str = field.value;
str = str.replace(/[^\x00-\xff]/g, "**");
if (str.length > maxlimit) {
// field.value = field.value.substring(0, maxlimit);
alert("视频标题超长,请更正!");
field.value = getByteOfNum(field.value, maxlimit);
}
}
function getByteOfNum(val, num) {
var ch, bytenum = 0;
var rs = "";
var pt = /[^\x00-\xff]/;
for (var i = 0; i < num; i++) {
ch = val.substr(i, 1);
if (ch.match(pt)) {
bytenum += 2;
if (bytenum > num) {
return rs;
}
}
else {
bytenum += 1;
}
rs += ch;
if (bytenum == num) {
return rs;
}
}
return rs;
}