小编mag*_*tte的帖子

使用公制前缀(如1.5K,1M,1G等)格式化javascript编号

我想使用带有3位有效数字的Metric Prefix来显示数字,如下所示:

1 shows as 1
999 shows as 999
1000 shows as 1K
999000 shows as 999K
1000000 shows as 1M
1500000 shows as 1.5M
1000000000 shows as 1G
etc...
Run Code Online (Sandbox Code Playgroud)

我可以编写自己的javascript函数来执行此操作,但我想知道是否有一种标准方式来格式化这样的数字?

javascript formatting

9
推荐指数
1
解决办法
6082
查看次数

使用.SetValidator()时,FluentValidation.Net不会产生客户端不显眼的验证

我正在尝试让客户端验证适用于使用编辑器模板的页面.

我的视图模型的简化示例是:

[Validator(typeof(ValidationTestModelValidator))]
public class ValidationTestModel
{
    public string Name { get; set; }

    public string Age { get; set; }

    public ChildModel Child { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

儿童模型是例如:

public class ChildModel
{
    public string ChildName { get; set; }

    public string ChildAge { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我的验证器是例如:

public class ValidationTestModelValidator : AbstractValidator<ValidationTestModel>
{
    public ValidationTestModelValidator()
    {
        RuleFor(m => m.Name)
            .NotEmpty()
            .WithMessage("Please enter the name");

        RuleFor(m => m.Age)
            .NotEmpty()
            .WithMessage("Please enter the age");

        RuleFor(m => m.Age)
            .Matches(@"\d*")
            .WithMessage("Must …
Run Code Online (Sandbox Code Playgroud)

fluentvalidation asp.net-mvc-3

8
推荐指数
1
解决办法
3863
查看次数

如何使用具有IEnumerable <T>类型属性的UIHint创建EditorTemplate

在MVC中,您可以为其创建编辑器模板T,然后当您想要为类型属性渲染编辑器时,IEnumerable<T>您可以简单地执行此操作

Html.EditorFor(m => m.MyListOfT)
Run Code Online (Sandbox Code Playgroud)

这样做的好处是,输入框架会自动创建名称,然后在回发模型绑定时,所有工作都很好.

我的问题是:当你有多种类型的编辑器模板时,你如何做到这一点?

我尝试过使用UIHint(),但它似乎只允许您针对列表指定UIHint,而不是列表中的每个项目.这意味着您必须使用foreach()循环为列表创建EditorTemplate,然后您错过了良好的自动命名和模型绑定.

我在这里错过了什么?

该模型是例如

public class MyViewModel
{
    public IEnumerable<SomeType> SomeProperty { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

理想情况下,我想做的事情如下:

public class MyViewModel
{
    [UIHint("SomeTypeTemplate")]
    public IEnumerable<SomeType> SomeProperty { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

并自动应用于列表中的所有元素,以便我可以使用以下内容进行渲染:

Html.EditorFor(m => m.SomeProperty)
Run Code Online (Sandbox Code Playgroud)

mvc-editor-templates razor c#-4.0 asp.net-mvc-4

8
推荐指数
1
解决办法
6631
查看次数

在IE11中鼠标滚轮滚动时不会触发mouseleave事件

使用鼠标滚轮向下滚动页面时,在移动光标之前,不会在IE11中触发mouseleave事件.适用于谷歌浏览器.

jsFiddle:http://jsfiddle.net/tonyleeper/5vwf65f7/

HTML

<div class="box">Move the mouse cursor inside this box and observe the mouseenter event fires (background goes green). Next, use the mouse wheel to scroll down without moving the mouse cursor position, observe the mouseleave event doesn't fire. Finally, move the mouse cursor even a little, say 1px, and observe that the mouseleave event then fires</div>
Run Code Online (Sandbox Code Playgroud)

CSS

.box {
    font-family: arial;
    font-size: 16px;
    width: 300px;
    height: 200px;
    background-color: #000077;
    color: #ffffff;
}
Run Code Online (Sandbox Code Playgroud)

JavaScript的

var box …
Run Code Online (Sandbox Code Playgroud)

javascript jquery scroll mouseleave internet-explorer-11

8
推荐指数
1
解决办法
2337
查看次数

仅当元素溢出时才将特定样式应用于该元素

有没有办法有条件地将特定样式应用于元素溢出?

例如,如果我说:

<div>
    This text is very long, no really it is extremely long; it just goes on and on and on and on. You might say it's a bit like the Duracell(R) bunny, but without the batteries, and the floppy ears.
</div>
Run Code Online (Sandbox Code Playgroud)

div {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

// TODO: is there any way to only apply this rule if the text is overflowing?
div {
    background-color: red;
}
Run Code Online (Sandbox Code Playgroud)

有没有办法使用纯 CSS 使背景颜色:红色规则仅在文本溢出时适用?

注意:我可以看到一种使用 javascript 执行此操作的方法;我只是想知道是否有一个纯 …

html css

7
推荐指数
0
解决办法
2174
查看次数

选项卡时如何将焦点设置为子窗口和开启窗口

在另一个浏览器选项卡中,如何将焦点设置回父窗口?我试过了:

window.opener.focus();
Run Code Online (Sandbox Code Playgroud)

无济于事.它似乎只在窗口没有停靠时工作.

我需要在Chrome,IE9/10,Firefox和Safari中使用它.

Internet Explorer似乎也有问题将焦点设置到子窗口.例如,使用时:

var windowRef = window.open(url);
Run Code Online (Sandbox Code Playgroud)

然后从同一个标签:

windowRef.focus(); // ok in Chrome, doesn't seem to work in IE...
Run Code Online (Sandbox Code Playgroud)

javascript browser

7
推荐指数
1
解决办法
3383
查看次数

将可滚动元素上的内部div的宽度设置为可滚动宽度的100%

如何使此内容div的宽度等于可滚动区域的宽度?

<div class="scrollable">
    <div class="content">short</div>
    <div class="content">very looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong text</div>
</div>
Run Code Online (Sandbox Code Playgroud)

用CSS:

.scrollable {
    width: 300px;
    height: 300px;
    overflow: auto;
}

.content {
    background-color: lightblue;
    white-space: nowrap;
}
Run Code Online (Sandbox Code Playgroud)

jsFiddle:http://jsfiddle.net/XBVsR/12/

问题:如果你滚动,你可以看到背景并没有像往常一样.

我试过设置宽度:100%,溢出:可见等,但无济于事.

编辑:我已经更新,以明确我不希望文本包装 - 我希望整个事情的水平滚动.

css html5 css3

7
推荐指数
1
解决办法
2628
查看次数

Google Chrome时间轴视图,非常慢的绘制操作,包含大量更新层树调用

我看到一个过度的绘画操作,需要1秒多的时间才能在Google Chrome中渲染.我有什么方法可以进一步诊断根本原因是什么?我可以看到它是由大量调用"更新层树"引起的,但我不知道从哪里开始.代码只是在滚动事件中处理的单个DOM节点上替换了一些innerHTML,所以我希望单个重新计算样式然后单个绘制,为什么我会看到所有这些更新层树和单独的绘制调用?

在此输入图像描述

google-chrome repaint

7
推荐指数
1
解决办法
1022
查看次数

OpenCover/NUnit找不到PDB文件

我正在使用OpenCover http://nuget.org/packages/opencover并编写了以下批处理文件来运行单元测试并生成代码覆盖率统计信息:

echo off

echo ***************************
echo *** Running NUnit tests ***
echo ***************************
"..\packages\OpenCover.4.0.804\OpenCover.Console.exe" -register:user -target:"..\NUnit 2.6\bin\nunit-console-x86.exe" -targetargs:"..\Web.UnitTests\bin\Debug\Web.UnitTests.dll"  -output:coverage.xml

echo **************************************
echo *** Generating coverage statistics ***
echo **************************************
"..\packages\ReportGenerator.1.6.0.0\ReportGenerator.exe" "-reports:coverage.xml" "-targetdir:%CD%"

echo ***********************************
echo *** Launching Internet Explorer ***
echo ***********************************
start "C:\Program Files (x86)\Internet Explorer\iexplore.exe" "%CD%\Index.htm"

pause
Run Code Online (Sandbox Code Playgroud)

但是,当我运行批处理文件时,我收到错误:

Committing...
No results - no assemblies that matched the supplied filter were instrumented
    this could be due to missing PDBs for the assemblies that match the filter
    please …
Run Code Online (Sandbox Code Playgroud)

.net nunit opencover

6
推荐指数
1
解决办法
4487
查看次数

适用于Visual Studio 2012的jsDoc intellisense

Visual Essentials的Web Essentials表示它支持jsDoc intellisense,但我看不到任何启用它的选项,它似乎没有做任何事情.

任何想法如何打开它?或者有人可以建议替代扩展吗?

非常感谢,

jsdoc visual-studio-2012 web-essentials

6
推荐指数
1
解决办法
4847
查看次数