JS 阻止事件冒泡
摘要:冒泡事件就是:你给父元素绑定了一个事件,你点击子元素也会触发这个事件,因为事件是向上冒泡的,阻止冒泡的方法最常见的方法有两种:1.if(event.target == this)使用这个判断就可以确定你点击的元素是否是事件触发的来源,这样就会阻止冒泡事件。$('#container button').click(function(event){ if(event.target==this){ ...... } }) 2.event.stopPropagation()使用这个方法的作用是阻止事件冒泡,阻止你对长辈元素的影响,但不能阻止后代元素对你的影响。$('#co...
阅读全文
posted @
2013-08-22 18:36
Mr.Young
阅读(1647)
推荐(0) 编辑
ASP.NET MVC验证DateTime的问题
摘要:今天碰到一个Bug,在IE8中,日期验证失效,输入正确的日期格式也会验证失败,提示:xxx必须是日期格式(the field xxx must be a date)最终找到问题所在:jquery.validate.js // http://docs.jquery.com/Plugins/Validation/Methods/date date: function( value, element ) { return this.optional(element) || !/Invalid|NaN/.test(new Date(value).toString()); },这段代码会有什么...
阅读全文
posted @
2013-08-13 13:38
Mr.Young
阅读(1256)
推荐(1) 编辑
如何将图片嵌入到Html中
摘要:将图片内嵌入到Html中,最好的方法就是用Base64 string.例如:下面做一个MVC的例子,非常简单:1.获取图片: string path = Server.MapPath("/Images/img1.png"); Image img = Image.FromFile(path);2.写一个扩展方法,将Image对象转换成Base64String public static string ToBase64(Image image, ImageFormat format) { using (v...
阅读全文
posted @
2013-08-09 15:50
Mr.Young
阅读(4633)
推荐(0) 编辑
Linq使用中的ToList注意事项
摘要:在使用Linq时,如果查询逻辑太复杂,可以拆分为多个Linq查询,下一个Linq在上一个Linq查询的结果上继续操作,这样逻辑清晰,又不会出错。但在使用ToList的时候需要注意,最常见碰到的错误是:LINQ to Entities does not recognize the method 'System.Collections.Generic.List`1[xxx] ToList[xxx](System.Collections.Generic.IEnumerable`1[xxx])' method, and this method cannot be translated
阅读全文
posted @
2013-08-08 18:21
Mr.Young
阅读(2371)
推荐(0) 编辑