我有一个带有这样的文本框的表单:
<html>
<head>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
</head>
<body>
<input type="text" id="myTextBox" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我在myTextBox中输入内容时,该值可用$("#myTextBox").val()
,但如果我这样做则不会显示$("body").html()
.我怎样才能获取html字符串和更新的表单值?谢谢!
Nor*_*ner 18
你可以使用这个.attr()
功能.
例:
$("input").each(function(){
$(this).attr("value", $(this).val());
});
Run Code Online (Sandbox Code Playgroud)
在此之后你可以做到:
$("body").html();
Run Code Online (Sandbox Code Playgroud)
这应该工作.
Coi*_*sox 15
$('[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; });
Run Code Online (Sandbox Code Playgroud)
然后
$("body").html()
Run Code Online (Sandbox Code Playgroud)