我有 jquery 包:
bundles.Add(new ScriptBundle("~/bundle/jquery").Include(
ScriptsPath("jquery-2.0.3.js"),
ScriptsPath("jquery.validate.js"),
ScriptsPath("jquery.validate.unobtrusive.js"),
ScriptsPath("jquery-ui-1.10.3.js"),
ScriptsPath("jquery.validate.unubtrusive.config.js"),
ScriptsPath("jquery.easing.1.3.js "),
ScriptsPath("jquery.unobtrusive-ajax.min.js"),
ScriptsPath("jquery.validate.custom.attributes.js") ...
在用户注册页面上,我有登录和注册表单,因此表单输入的名称中有 Register.
和 Login.
前缀。基本上它看起来像:
<input type="text" ... id="Register_Email" name="Register.Email" />
<input type="password" ... id="Register_Password" name="Register.Password" />
当我在 Release模式下发布我的应用程序时,我在 bundle 文件中收到此错误:
这显然是因为输入名称中的点。如何保存点并解决此问题?我已经尝试过 BundleTable.EnableOptimizations = false;
但它没有帮助,我不认为这是合适的解决方案,因为它破坏了 bundle 的目的。另请注意,问题仅发生在发布 模式下。
编辑:
bundle 文件列表包含一个我自己的脚本文件,它包含我的 ForbidHtmlAttribude
的客户端验证逻辑:
jquery.validate.custom.attributes.js
jQuery.validator.unobtrusive.adapters.add(
'forbidhtmlattribute',
['htmlregexpattern'],
function (options) {
options.rules['forbidhtmlattribute'] = options.params;
options.messages['forbidhtmlattribute'] = options.message;
}
);
jQuery.validator.addMethod('forbidhtmlattribute', function (value, element, params) {
if (value === null || value === undefined) return true;
var regex = params['htmlregexpattern'];
return !value.match(regex);
}, '');
最佳答案
问题很可能出在这一行:
if (value === null || value === undefined) return true;
试着改成
if ((value === null) || (value === undefined)) return true;
解释:
MS 缩小算法删除了不必要的空格。它“知道”语言关键字,如“var”或“return”,但“null”不是其中之一。因此,缩小的行将是
if(value===null||value===undefined)return true;
现在从 JavaScript 的角度来看,我们有一个名为“null||value
”的奇怪变量。将条件括在括号中解决了问题:
if(value===null)||(value===undefined)return true;
关于c# - 由于 Release模式下的包缩小,jQuery 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29735987/