这让我疯了.
无论我尝试什么,Internet Explorer都会切换到IE7标准文档模式.我尝试使用HTML5 boilet plate和HTML5 reset(他们自己的站点进入Quirks模式)尝试剥离我的代码以使其无法尝试并使其表现出来.
我还添加了元标记,无论如何都应该强制IE使用它的最新版本,但是根据W3C,所做的一切都使得我的标记无效.
这就是我的意思; 我错过了什么?
<!doctype html>
<!--[if IE 7 ]> <html class="ie7> <![endif]-->
<!--[if IE 8 ]> <html class="ie8> <![endif]-->
<!--[if gt IE 8]><!--><html><!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<p>Test text</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
编辑
我通过以下建议找到了解决方案.这个建议不起作用,但确实引起了我的回答.这可能不是100%适合每个人,因为它在body
标签上强加了一个类而不是html
,但它适用于我,似乎适用于IE.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="css/style.css">
</head>
<!--[if IE 7 ]> <body class="ie7> <![endif]-->
<!--[if IE 8 ]> <body class="ie8> <![endif]-->
<!--[if …
Run Code Online (Sandbox Code Playgroud) 我正在寻找关于保持我的JavaScript(jQuery)函数的最佳方法的一些建议.
我在MVC/razor开发,因此有一个布局页面.我在这里包含了我的jQuery库和外部JavaScript文件,因此它可以在每个页面中使用.
这很好用,但我现在非常清楚我在每页都添加了近300行JS,其中一半可用于其中任何一页.
一个函数不在外部文件中,而是位于HTML内部,因为我需要使用我的剃刀代码中设置的变量.
关于这种安排,我有几个问题:
(document).ready
呢?如果要使用我所包含的所有JavaScript,是否需要使用它?我相信这不仅仅是一个黑色和白色的答案,而是我想在继续之前考虑我的所有选择.即使它工作正常,我也不禁觉得有更好/更清洁的方式.
我目前正在使用MVC4数据注释来处理验证.我正在开发一个非常国际化的网站,因此我将所有文本保存在资源文件中.
我还想在资源文件中保留正则表达式以进行验证,这样我就可以使用相同的代码来检查,例如,Post Codes(UK)和Zip Codes(US),只需使用不同的RegEx(以及不同名称的资源等) ).
我有以下属性已经从资源文件中提取错误消息.我怎样才能从资源文件中获取正则表达式?
[RegularExpression(@"^[\w]{1,2}[0-9]{1,2}[\w]?\s?[0-9]{1,2}[\w]{1,2}$", ErrorMessageResourceType = typeof(Resources.ValidationMessages), ErrorMessageResourceName = "validPostcode")]
Run Code Online (Sandbox Code Playgroud)
编辑(再次)
我现在在哪里
按照下面的答案和一些额外的搜索,我有以下内容:
在Global.asax.cs
我添加了以下行,以确保调用客户端验证
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(LocalisedAttribute), typeof(RegularExpressionAttributeAdapter));
Run Code Online (Sandbox Code Playgroud)
在我的模型中,我调用了属性扩展
[Localised(typeof(Resources.FormValidation), "postcodeRegEx", "postcodeMsg")]
Run Code Online (Sandbox Code Playgroud)
最后,本地化正则表达式验证的属性扩展
public class LocalisedAttribute : RegularExpressionAttribute
{
public LocalisedAttribute(Type resource, string regularExpression, string errorMessage)
: base(GetRegex(regularExpression))
{
ErrorMessageResourceType = resource;
ErrorMessageResourceName = errorMessage;
}
private static string GetRegex(string value)
{
return Resources.FormValidation.ResourceManager.GetString(value);
}
}
Run Code Online (Sandbox Code Playgroud)
这是有效的,但只是我第一次在启动应用程序时使用它.
我将打开另一个问题来解决这个问题 - 它与原始请求没有直接关系,似乎与大多数人的实现没有关系,似乎并不特定于数据注释.
asp.net asp.net-mvc custom-attributes data-annotations asp.net-mvc-4
我正在使用我的MVC 4应用程序中的数据注释来处理验证.这样做的一个要求是完全本地化所有错误消息和正则表达式.
为了做到这一点,我写了一个属性扩展,如下所示.
视图:
@Html.LabelFor(m => m.Postcode, new { @class = "input-label", @for = "valid-postcode" })
@Html.TextBoxFor(m => m.Postcode, new { type = "text", id = "valid-postcode", autocomplete = "off" })
@Html.ValidationMessageFor(m => m.Postcode)
Run Code Online (Sandbox Code Playgroud)
模型:
// Postcode
[Required(ErrorMessageResourceType = typeof(Resources.FormValidation), ErrorMessageResourceName = "requiredMsg")]
[Localised(typeof(Resources.FormValidation), "postcodeRegEx", "postcodeMsg")]
[Display(Name = "postcode", ResourceType = typeof(Resources.FormLabels))]
public string Postcode { get; set; }
Run Code Online (Sandbox Code Playgroud)
属性扩展:
public class LocalisedAttribute : RegularExpressionAttribute
{
public LocalisedAttribute(Type resource, string regularExpression, string errorMessage)
: base(Resources.FormValidation.ResourceManager.GetString(regularExpression))
{
ErrorMessageResourceType = …
Run Code Online (Sandbox Code Playgroud) asp.net-mvc localization data-annotations asp.net-mvc-4 asp.net-mvc-5
我有一个可滚动的div,我想每X秒向下滚动50个像素.那很好,很有效.
我还有一个单独的功能,当它到达底部时将div滚动回顶部.也很好; 工作.
现在,我需要将两者结合起来,以便忽略scrollldown,直到我们再次滚动到顶部.
我在这里有一个"工作"的例子,因为你会看到它有一些非常疯狂的行为:http://jsfiddle.net/JVftf/
window.setInterval(scrollit, 3000);
function scrollit() {
$('#scroller').delay(2000).animate({ scrollTop: $("#scroller").scrollTop() + 50 }, 'slow');
}
$('#scroller').bind('scroll', function () {
if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
$('#scroller').delay(2000).animate({ scrollTop: 0 }, 1000);
}
});
Run Code Online (Sandbox Code Playgroud) 我用过preventDefault
像这样的元素事件:
$('#element').click(function (e) {
do stuff...
});
Run Code Online (Sandbox Code Playgroud)
现在,我有一个函数,它已经在我想要使用的参数,preventDefault
但我不知道如何:
<a href="#services" id="services_link" class="services" onclick="sectionScroll('services')">Services</a>
function sectionScroll(id) {
history.pushState(null, null, '#' + id);
$('html, body').animate({
scrollTop: $("#" + id).offset().top
}, 1000);
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用return false,但是当点击链接时,这会导致一些闪烁.
如何添加preventDefault
上述功能?
编辑
我最初的问题是在具有其他参数的函数中使用preventDefault.我最后不需要使用内联javascript(它看起来似乎没有办法避免它),所以这就是我使用的.我觉得它很整洁:
<a href="#services" class="menu-link">Services</a>
$('.menu-link').click(function (e) {
e.preventDefault();
var location = $(this).attr('href');
history.pushState(null, null, location)
$('html, body').animate({
scrollTop: $(location).offset().top
}, 1000);
});
Run Code Online (Sandbox Code Playgroud) 我对MVC和剃刀很新,但到目前为止我很享受.有一两个我遇到麻烦的基础知识,所以希望这对某人来说很容易.
我正在创建一个新变量并替换空格.但是,这似乎根本不起作用; 我自己添加到字符串的空间仍然存在.我不能简单地在这一点上使用下划线作为两者Address1
并且Postcode
也可能包含空格,因此替换是必不可少的.
@{
var mapAddress = Model.Address1 + ", " + Model.Postcode;
mapAddress.Replace(" ", "_");
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用preventDefault,以便在提交带有"帐号"作为输入值的表单时不会发生任何事情.
对于我所做的所有阅读,我看不出问题.我怀疑我刚刚盯着它看太久而且遗漏了一些非常明显的东西.帮我今天准时离开办公室!
这里的非工作代码示例:http://jsfiddle.net/sX52r/
HTML
<form action="/" id="AccSearch" method="post">
<input type="text" name="AccountNumber" ID="AccountNumber" class="lookup_field" value="Account number" onfocus="if(this.value=='Account number'){this.value=''}"
onblur="if(this.value==''){this.value='Account number'}">
<input type="image" id="AccSearchSubmit" src="/Images/search.png" onmousedown="this.src='/Images/search_down.png'" onmouseup="this.src='/Images/search.png'" onmouseout="this.src='/Images/search.png'" alt="Submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
JS
$('#AccSearchSubmit').click(function (e) {
if ($('#AccountNumber').val == 'Account number') {
e.preventDefault();
alert("BOING!");
}
});
Run Code Online (Sandbox Code Playgroud) 我有一个函数,可以为一个数字添加一千个分隔符,但是当传入小数时它不能正常工作:
function thousandSep(val) {
return String(val).split("").reverse().join("")
.replace(/(.{3}\B)/g, "$1,")
.split("").reverse().join("");
}
Run Code Online (Sandbox Code Playgroud)
如果我传入10000,我会按预期获得10,000.
但是,通过10,000.00我得到1,000,0.00.
如何修改处理小数的函数?
我希望能够显示当前节点的父标题.
网站地图:
<mvcSiteMapNode title="Main Site Tile" controller="Home" action="Index">
<mvcSiteMapNode title="Some site section" controller="Section" action="Index">
<mvcSiteMapNode title="Some page" controller="Section" action="Page1" />
<mvcSiteMapNode title="Some other page" controller="Section" action="Page2" />
</mvcSiteMapNode>
</mvcSiteMapNode>
Run Code Online (Sandbox Code Playgroud)
因此,在'Page1'上我可以使用以下方式显示标题(某些页面):
Html.MvcSiteMap().SiteMapTitle()
Run Code Online (Sandbox Code Playgroud)
大.但是,我还想在我的_Layout页面中显示父节点(某些网站部分)的标题,所以如果我查看'Page1'或'Page2'(或者实际上嵌套在其中的任何视图),这将显得相同.
这可能吗?
javascript ×5
asp.net-mvc ×4
jquery ×4
.net ×1
architecture ×1
asp.net ×1
forms ×1
html ×1
html5 ×1
localization ×1
placeholder ×1
razor ×1
string ×1