我有以下内容:
<html>
<head>
</head>
<body>
<div>
<form method="post">
<div id="questions">
<label for="question-6">Name of Course:</label>
<input type="text" name="name_of_course[response]" value="" id="question-6" class="required">
<label class="control-label" for="reporting-year">Reporting Year: </label>
<select name="reporting_year" id="reporting-year">
<option value="-1" selected="selected">Select option...</option>
<option value="4">2013-2014</option>
<option value="1">2012-2013</option>
<option value="2">2011-2012</option>
<option value="3">2010-2011</option>
</select>
</div>
<input type="submit" name="submit" value="Save Entry" class="btn">
</form>
</div>
<script src="//code.jquery.com/jquery.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script>
$(function(){
jQuery.validator.addMethod("notEqual", function(value, element, param) {
return this.optional(element) || value !== param;
}, "Please select an option");
$('form').validate({
rules:{
'reporting_year': {
notEqual: "-1"
}
} …Run Code Online (Sandbox Code Playgroud) javascript jquery jquery-validate internet-explorer-7 compatibility-mode
全部,
我正在开发一个非常简单的 Web API 2 项目。由于某种原因,我无法让 CORS 正常工作,除非我将其放入 web.config 文件中。我按照MSDN 文章和这篇ASP.NET 文章中的说明进行操作,但我一定遗漏了一些东西。
全局.asax.cs
protected void Application_Start()
{
WebApiConfig.Register(GlobalConfiguration.Configuration);
}
Run Code Online (Sandbox Code Playgroud)
WebApiConfig.cs
public static void Register(HttpConfiguration config)
{
config.EnableCors(new EnableCorsAttribute("*","*","*"));
config.MapHttpAttributeRoutes();
}
Run Code Online (Sandbox Code Playgroud)
JavaScript
$.ajax({
url: '//myapidomain.com/buildings'
}).done(function (data) {
var theList = $('.buildings'),
theListHTML = "",
response = JSON.parse(data);
$.each(response.Buildings.Data, function () {
theListHTML += '<li>' + this.Description + '</li>';
});
theList.html(theListHTML);
});
Run Code Online (Sandbox Code Playgroud)
我已经查看了几乎每一个 Stack Overflow(例如这个)和 MSDN 论坛帖子(例如这个),据我所知,这应该有效。该应用程序托管在运行 4.0 的 IIS 8 …
我无法正确格式化2位数日期作为4位数日期.
我有一个文本输入字段:
<input type="text" value="" class="date"/>
Run Code Online (Sandbox Code Playgroud)
然后我想在用户输入日期后以"mm/dd/yyyy"格式对其进行格式化.所以我有一个onChange事件:
$('.date').on('change',function(){
var date = new Date($(this).val());
$(this).val((date.getMonth()+1)+'/'+date.getDate()+'/'+date.getFullYear());
});
Run Code Online (Sandbox Code Playgroud)
好的,所以现在出现了奇怪的事情(我将使用12/12/12作为示例日期):
1)getFullYear()在所有IE,FF中返回1912.Chrome返回2012年.
2)getYear()在IE中返回112,Chrome.FF返回12.
因此,此时似乎唯一的选择是嗅探用户代理,并相应地使用它.反正在嗅探UA吗?
使用jQuery和jQuery URL插件.
我有以下代码:
$('#secondary-nav > li > ul > li > a').each( function() {
var aHref = new String( $(this).attr('href') );
alert (aHref);
var wUrl = new String( $.url().attr('file') );
alert (wUrl);
alert ( aHref === wUrl );
});
Run Code Online (Sandbox Code Playgroud)
aHref和wUrl都是字符串对象(我已使用instanceof确认).但比较结果却是错误的.代码在"pageA.html"上,其中一个锚点的href是"pageA.html",但它从未计算为true.