小编Dav*_*rák的帖子

.append之后的jQuery函数

如何在jQuery .append完成后调用函数?

这是一个例子:

$("#root").append(child, function(){
   // Action after append is completly done
});
Run Code Online (Sandbox Code Playgroud)

问题:当附加复杂的DOM结构时,在追加函数回调中计算根元素的新大小是错误的.假设DOM仍未完全加载,只有添加的复杂DOM的第一个子元素.

jquery

83
推荐指数
7
解决办法
14万
查看次数

之前的图像大小是在DOM中

在将其放入DOM之前,如何获得图像大小?

var imgLoad = $("<img />");
$(imgLoad).attr("src", ImageGallery.ImagesList[index] + "?" + new Date().getTime());
$(imgLoad).unbind("load");
$(imgLoad).bind("load", function () {

   // Get image sizes
   alert(imgLoad.width()); // RETURN 0

});
Run Code Online (Sandbox Code Playgroud)

jquery

12
推荐指数
1
解决办法
1万
查看次数

JQuery on Click事件函数调用

我想从jQuery Click事件中调用一个函数.我尝试下面的注释不起作用.

$(".menu_link").click(GetContentAndSlide());
Run Code Online (Sandbox Code Playgroud)

什么是正确的注释?

jquery

10
推荐指数
1
解决办法
2万
查看次数

CSS - 标题 - 始终是底部页脚和100%内容

<body> 
    <div id="wrap">
        <div id="header">
            HEADER
        </div>
        <div id="inner-wrap">
            <div id="content">
               CONTENT
            </div>
        </div>
        <div id="footer">
            FOTTER
        </div>
    </div> </body>
Run Code Online (Sandbox Code Playgroud)

和CSS:

html { height:100%; max-height:100%; }

body {
    margin:0;
    padding:0;
    height:100%;
    max-height: 100%;
}

#wrap {
    min-height:100%;
    height: 100%;
    position:relative;
}
* html #wrap { height:100% }

#inner-wrap {
    padding-bottom:50px;
    min-height: 100%;
}
#inner-wrap:after {
    content:" ";
    display:block;
    clear:both;

}
* html #inner-wrap {
    height:100%;
}

#header
{
    width: 100%;
    background-color: #C0C0C0;
    height: 16px;
    color: White;
    text-align: center;
    position: relative; …
Run Code Online (Sandbox Code Playgroud)

html css

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

使用实体框架模拟存储库

我正在使用mog模拟一个LINQ to SQL的存储库,如下所示:

public static IProductsRepository MockProductsRepository(params Product[] prods){
    // Generate an implementer of IProductsRepository at runtime using Moq
    var mockProductsRepos = new Mock<IProductsRepository>();
    mockProductsRepos.Setup(x => x.Products).Returns(prods.AsQueryable());
    return mockProductsRepos.Object;
}

public interface IProductsRepository{
    IQueryable<Product> Products { get; }
    void SaveProduct(Product product);
    void DeleteProduct(Product product);
}
Run Code Online (Sandbox Code Playgroud)

如果我像这样使用它,我如何为Entity框架更改此函数:

public interface IProductsRepository : IEntities{
    EntityState GetEntryState(object entry);
    void SetEntryState(object entry, EntityState state);
    void Commit();
}

public interface IEntities{
    DbSet<Product> Products { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

现在我正在使用DbSet.

entity-framework moq

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

jQuery绑定("加载")

var imgLoader = $("<img />");
$(imgLoader).attr("src", "http://localhost/malevil/Content/Images/img_adrenalin.jpg");

$(imgLoader).unbind('load');
$(imgLoader).bind('load', function () {
    alert("event fired");
});
Run Code Online (Sandbox Code Playgroud)

但这项工作仅限于Chrome,问题出在哪里?在IE中,Firefox和Opera加载事件从未被解雇.

javascript jquery

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

将List <Enum>参数传递到ASP.NET MVC3中的自定义操作筛选器

我如何解析List自定义动作过滤器(如输入参数)?

public class CustomFilter : ActionFilterAttribute
{

    public List<MyEnumType> InputParameter { get; set; }

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {         
        base.OnActionExecuting(filterContext);
    }
}

[CustomFilter(InputParameter = new List<MyEnumType>() { MyEnumType.Type } )]
public SomeActionInController()
{
}
Run Code Online (Sandbox Code Playgroud)

我得错了错误

'InputParameter' is not a valid named attribute argument because it is not a valid attribute parameter type
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-3

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

ASP.NET MVC3停止在自定义AuthorizeAttribute中执行操作/控制器

如何在没有重定向的情况下停止执行操作/控制器,并且仅返回带有statusCode的响应

public class MainAuthorizationFilter : AuthorizeAttribute
{
    public override void OnAuthorization(AuthorizationContext filterContext)
    {
        ... [my Authorization login] ...

        if([Authorization fail])
        {
             if (filterContext.HttpContext.Request.IsAjaxRequest())
             {
                 filterContext.HttpContext.Response.StatusCode = 401;
                 // HERE I want stop executing action/controller because I want return only statusCode
             }
             else
             {
                  // In non-ajax request I just redirect me request and action/contoller isn't executed
                  filterContext.Result = new RedirectToRouteResult("Error", new RouteValueDictionary { { "errorCode", errorCode } });
             }
        }
    }

    base.OnAuthorization(filterContext);

}

[MainAuthorizationFilter]
public ActionResult CreateFolder(...)
{
   CreateFolder(...);
}
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-3

5
推荐指数
1
解决办法
7245
查看次数

SignalR javascript回调无法正常工作

我有集线器类:

public class ChatHub : Hub
{
    // Send message
    public void Send(string message)
    {
        Clients.addMessage(DateTime.Now.ToString("HH:mm:ss") + " " + message);
    }
}
Run Code Online (Sandbox Code Playgroud)

和javascript:

// Proxy created on the fly
var chat = $.connection.chatHub;

// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function(message) {
    alert("message:" + message);
    $('#chat').append('<div>' + message + '</div>');
};


$("#sendButton").click(function () {

    // Call the chat method on the server
    chat.send($('#message').val())
        .done(function () {
            console.log('Success!')
        })
        .fail(function (e) …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc-3 signalr

5
推荐指数
1
解决办法
3132
查看次数

如何获取Generic参数的类型?

我怎样才能获得泛型参数的类型?

例如:

void Example<T>()
{
  // Here I want to get the type of T (and how can I get if T is a primitive 
  // kind (int,bool,string) not class)
} 
Run Code Online (Sandbox Code Playgroud)

c# generics

4
推荐指数
2
解决办法
453
查看次数