如何在jQuery .append完成后调用函数?
这是一个例子:
$("#root").append(child, function(){
// Action after append is completly done
});
Run Code Online (Sandbox Code Playgroud)
问题:当附加复杂的DOM结构时,在追加函数回调中计算根元素的新大小是错误的.假设DOM仍未完全加载,只有添加的复杂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 Click事件中调用一个函数.我尝试下面的注释不起作用.
$(".menu_link").click(GetContentAndSlide());
Run Code Online (Sandbox Code Playgroud)
什么是正确的注释?
<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) 我正在使用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.
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加载事件从未被解雇.
我如何解析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) 如何在没有重定向的情况下停止执行操作/控制器,并且仅返回带有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) 我有集线器类:
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) 我怎样才能获得泛型参数的类型?
例如:
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) jquery ×4
asp.net-mvc ×2
asp.net ×1
c# ×1
css ×1
generics ×1
html ×1
javascript ×1
moq ×1
signalr ×1