我看到.on()jQuery 1.7中有一个新方法取代了.live()早期版本.
我很想知道它们之间的区别以及使用这种新方法的好处.
随着jQuery 1.6的发布,关于SO的建议一般是开始使用prop(),你曾经使用attr().
当我想要一个元素只读时会发生什么?
$('.control').prop('readonly', 'readonly');
$('.control').prop('readonly', true);
Run Code Online (Sandbox Code Playgroud)
这些似乎都没有使控制只读.将元素readonly作为规则的例外吗?
我注意到,在将事件处理程序绑定到javascript事件时,建议使用命名函数.当我的函数需要传递给this对象时,我该怎么做?
例如,如何通过直接调用来替换下面的匿名函数doFancyStuff:
$(document).on('change', 'input.fancy-textbox', function () {
doFancyStuff($(this));
});
function doFancyStuff($textbox) {
// fanciness
}
Run Code Online (Sandbox Code Playgroud)
如果你指出我可能打破上述代码的其他约定,请加分.
为了澄清,我想doFancyStuff()从多个地方调用我的例子中的方法,否则,我可以做这样的事情:
$(document).on('change', 'input.fancy-textbox', doFancyStuff);
function doFancyStuff() {
var $textbox = $(this);
// fanciness
}
Run Code Online (Sandbox Code Playgroud) 我一直无法向在Azure应用服务上运行的64位ASP.NET Core API发出请求.我得到的错误是:
未处理的异常:System.BadImageFormatException:无法加载文件或程序集'***.dll'.尝试加载格式不正确的程序.
我知道这意味着应用程序平台(64位)与其运行环境之间存在不匹配.我只是无法弄清楚如何更改App Service,因此它使用64位运行.
在Azure门户的应用程序设置中,我将Platform设置为64位:
但是当我检查Kudu时,运行时环境表明它在win8-x86下运行:
project.json
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"platform": "x64"
},
"runtimes": {
"win10-x64": {}
}
Run Code Online (Sandbox Code Playgroud)
一些问题
win8...在我的运行时配置project.json指定时是否重要win10...?据推测x86 vs x64很重要,但是它也需要是相同版本的windows,即.win8 vs win10.我想让用户只在一个TextBox中输入HTML.我理解可以ValidateRequest将页面指令更改为false以删除保护.
我猜这可以在页面上的任何TextBox中输入HTML.无论如何ValidateRequest="false"只适用于一个控件吗?
谢谢你的帮助.
我编写了一个EnumDropDownFor()帮助器,我想与EditorFor()一起使用.我刚刚开始使用EditorFor(),所以对模板的选择方式有点困惑.
我的Enum.cshtml编辑器模板如下:
<div class="editor-label">
@Html.LabelFor(m => m)
</div>
<div class="editor-field">
@Html.EnumDropDownListFor(m => m)
@Html.ValidationMessageFor(m => m)
</div>
Run Code Online (Sandbox Code Playgroud)
如果没有明确定义要使用的模板,是否有任何方法可以使用默认模板,只要将Enum传入EditorFor()?
我想在文本框初始化之后更改Bootstrap工具提示的位置:
// these don't work
$('#myTextbox').tooltip({ placement: 'left' });
$('#myTextbox').tooltip('options', 'placement', 'right' });
Run Code Online (Sandbox Code Playgroud)
有什么办法吗?如果是这样,我做错了什么?
设置MvcBuildViews为true我的.csproj文件后,为了在构建期间编译视图,我收到以下错误:
'/ temp'不是有效的IIS应用程序
我认为这指的'/ temp'是编译视图的路径.这是.csproj文件中的相关部分:
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
Run Code Online (Sandbox Code Playgroud)
我使用完整的IIS在我的本地机器上提供这个MVC 5网站(尚未在远程服务器上尝试过这个).我是否需要在IIS中设置一些内容以使其MvcBuildViews正常工作?
随着jQuery 1.6的发布,关于SO的建议一般是开始使用prop()你曾经使用过的地方attr().
当我想要禁用元素时会发生什么?
$('.control').prop('disabled', 'disabled');
$('.control').prop('disabled', true);
Run Code Online (Sandbox Code Playgroud)
这些似乎都没有禁用控件.禁用元素是规则的例外吗?
更新 并证明元素未被禁用的原因是因为我在上面的行之前运行了一行:
$('.control').removeProp('disabled');
Run Code Online (Sandbox Code Playgroud)
在启用控件时,我已经习惯了使用.removeAttr()这样的.removeProp就足够了.而是,使用以下来启用控件:
$('.control').prop('disabled', false);
Run Code Online (Sandbox Code Playgroud) 今天早上我在localhost的ASP.NET MVC 2站点上的一个CSS文件上返回302错误,我不知道会有什么改变导致这个.
localhost站点使用IIS 7.5,虽然我对IIS的经验有限,所以我没有太多关注那里可能发生的事情.
CSS文件的URL是:
http://localhost/MySite/Content/Site.css?v=16
Run Code Online (Sandbox Code Playgroud)
并且响应上的位置标头如下所示:
/MySite/Account/Login?ReturnUrl=%MySite%2fContent%2fSite.css%3fv%3d16&v=16
Run Code Online (Sandbox Code Playgroud)
这让我觉得MVC正在重定向静态文件或类似的东西,但是如果是这种情况,那么我希望我的所有图像,CSS和JavaScript文件都做同样的事情.以防万一,这是RegisterRoutes()Global.ascx 的简化版本:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("", "Account/{action}/", new { controller = "Account" });
routes.MapRoute("", "{action}", new { controller = "Home", action = "Index" });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Error",
"{*url}",
new { controller = "Home", action = "ResourceNotFound" }
);
}
Run Code Online (Sandbox Code Playgroud)
此外,如果我将我的CSS文件的名称更改为Site2.css并引用它,则会发生同样的事情. …
asp.net-mvc ×3
jquery ×3
iis ×2
jquery-1.6 ×2
.net-core ×1
64-bit ×1
asp.net ×1
azure ×1
coding-style ×1
editorfor ×1
javascript ×1
jquery-1.7 ×1
readonly ×1
routing ×1
tooltip ×1