Javascript 为什么.val(';';)要去掉单引号
我有以下jQuery代码Javascript 为什么.val(';';)要去掉单引号,javascript,jquery,Javascript,Jquery,我有以下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 r
$(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属性只包含默认值,而不包含实际的live值。这有什么问题吗
value
等于value='
。没有什么问题。它仍然是一个有效的HTML。重要的是内存中的值[…]空属性语法:只是属性名。值隐式地是空字符串。[…]
@t.niese哦,好吧,我不知道。好吧,所以问题是我的PHP代码,而不是jQuery。我认为它没有返回空值,因为stripped out=“”。我是个新手,能原谅你的无知。问题解决了。感谢所有回应的人。