作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将带有输入的表转换为值表。我创建了这个 JavaScript 函数,它适用于除带有类型复选框的输入之外的所有内容。
这是我当前的功能:
function PopulateHidden() {
$('#Units input').replaceWith(function () {
return this.value;
});
$('#Units select').replaceWith(function () {
return this.value;
});
var html = $("#Units").html();
$('#<%=UnitTableHtml.ClientID%>').val(html);
}
我尝试过此方法的各种版本:
$(".chk").replaceWith(function () {
alert(this.html());
if (this.prop('checked') == true) {
alert("YES");
return "Yes";
};
return "No";
});
但我一直将文本框的值设置为“on”而不是 true/false。我希望该值是"is"或“否”,但它没有进入 if 语句。为什么我无法将复选框的值作为 bool 值获取,有什么原因吗?
这是我定义复选框的方式:
<input type="checkbox" class="chk" style="width:20px;height:20px;"/>
最佳答案
所有人都称赞贾斯珀,因为我正在使用相同的建议构建这个 fiddle :需要 $(this)
而不是 this
关于javascript - 在输入类型复选框上使用 JQuery ReplaceWith,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27933628/
我是一名优秀的程序员,十分优秀!