jquery - 在网页上的文本输入字段中输入的 0 被重置为 null
问题描述
当我的网页上的文本输入字段的值为 0 时,它会变为 null 并且对于所有其他文本输入字符串都可以正常工作。
根据我的分析(使用 Chrome 调试器),POST 将数据正确保存为 0。但是,当向同一端点发出 GET 请求时,此时 0 值将更改为 null。
$.ajaxTransport("iframe", function(options, origOptions, jqXHR) {
var form = null,
iframe = null,
name = "iframe-" + $.now(),
files = $(options.files).filter(":file:enabled"),
markers = null,
accepts = null;
// This function gets called after a successful submission or an abortion
// and should revert all changes made to the page to enable the
// submission via this transport.
function cleanUp() {
markers.prop("disabled", false);
form.remove();
iframe.one("load", function() { iframe.remove(); });
iframe.attr("src", "javascript:false;");
}
// Remove "iframe" from the data types list so that further processing is
// based on the content type returned by the server, without attempting an
// (unsupported) conversion from "iframe" to the actual type.
options.dataTypes.shift();
// Use the data from the original AJAX options, as it doesn't seem to be
// copied over since jQuery 1.7.
// See https://github.com/cmlenz/jquery-iframe-transport/issues/6
options.data = origOptions.data;
if (files.length) {
form = $("<form enctype='multipart/form-data' method='post'></form>").
hide().attr({action: options.originalURL, target: name});
// If there is any additional data specified via the `data` option,
// we add it as hidden fields to the form. This (currently) requires
// the `processData` option to be set to false so that the data doesn't
// get serialized to a string.
if (typeof(options.data) === "string" && options.data.length > 0) {
$.error("data must not be serialized");
}
$.each(options.data || {}, function(name, value) {
if ($.isPlainObject(value)) {
name = value.name;
value = value.value;
}
$("<input type='hidden' />").attr({name: name, value: value}).
appendTo(form);
});
我希望我保存的输入值保持为 0,但它会更改为 null。
解决方案
推荐阅读
- c# - Linq 中的 Sql YEAR(),MONTH()
- expo - Sentry 找不到我的源代码
- lotusscript - LotusScript - AppendDocLink 不在 RichTextItem 中创建 doclink
- android - 更新 gradle 后出现 AAPT 错误
- c# - 入站循环控制变量越界?
- javascript - .addClass 在functions.php中的元素上
- stm32 - STM32 从特定的 NOR 块启动
- c++ - 以编程方式在任何按钮上应用 Qt 鼠标悬停按钮突出显示
- java - Katalon Studio Java jar 文件
- swift - 包含闭包的 Swift 数组