javascript - 为什么 .val('') 去掉单引号
问题描述
我有以下 jQuery 代码,
$(document).ready(function() {
$("#results").on('click', 'input:checkbox', function() {
// in the handler, 'this' refers to the box clicked on
var $box = $(this);
if ($box.is(":checked")) {
// the name of the box is retrieved using the .attr() method
// as it is assumed and expected to be immutable
var group = "input:checkbox[name='" + $box.attr("name") + "']";
// the checked state of the group/box on the other hand will change
// and the current value is retrieved using .prop() method
$(group).prop("checked", false);
$box.prop("checked", true);
$('#wp_theme_url').val($(this).val());
$('#wp_theme_slug').val($(this).data("themeslug"));
} else {
$box.prop("checked", false);
$('#wp_theme_url').val('');
$('#wp_theme_slug').val('');
}
});
});
但是,如果我取消选择一个复选框,它会从 value 属性中删除 ='' 导致
<input ... value>
代替
<input ... value=''>
任何想法为什么?
解决方案
value 属性仅包含默认值,而不包含实际的实时值。
推荐阅读
- hadoop - 蜂巢错误消息。有谁知道如何解决这一问题?
- swift - 表视图,视图控制器,表单元格零错误
- java - 在 v-server 上永久运行 jar 文件
- r - 按时间窗口条件组替换缺失值
- pandas - 变量序列的 Pandas 列
- java - 我可以在 OpenJDK 8 中使用 javafx/openjfx 吗?
- http-status-code-403 - 用户认证后的 Laravel nova v3.12 给出 403 Forbidden
- r - 如何将“MMM DD,YYYY”转换为正确的日期格式?
- google-apps-script - 处理 onSelectionChange 事件会导致进一步触发 onSelectionChange 事件
- android - KOTLIN :如何使用 ViewBinding 在函数中调用视图