我有一个带有如下文本框的表单:
<html>
<head>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
</head>
<body>
<input type="text" id="myTextBox" />
</body>
</html>
当我在myTextBox中输入内容时,该值在$("#myTextBox").val()
中可用,但如果我输入$("body").html()
,则不会显示。如何获取html字符串和更新后的表单值?谢谢!
发布于 2011-08-18 00:15:30
您可以使用.attr()
函数。
示例:
$("input").each(function(){
$(this).attr("value", $(this).val());
});
在此之后,您可以执行以下操作:
$("body").html();
这应该是可行的。
发布于 2013-04-05 11:38:54
$('[type=text], textarea').each(function(){ this.defaultValue = this.value; });
$('[type=checkbox], [type=radio]').each(function(){ this.defaultChecked = this.checked; });
$('select option').each(function(){ this.defaultSelected = this.selected; });
然后
$("body").html()
发布于 2011-08-18 00:07:57
$('input').each(function(){
$(this).attr('data-value-input', $(this).val());
});
然后你就可以得到你的html了。
var bodyHtml = $('body').html().toString().replace('data-value-input', 'value');
就是这样。
https://stackoverflow.com/questions/7095956
复制相似问题