本文介绍了jQuery的HTML()不会返回更改的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< html> < head> < script type =text / javascriptsrc =jquery-1.6.2.js>< / script> < / head> < body> < input type =textid =myTextBox/> < / body> < / html>
当我在myTextBox中输入某些内容时,可以使用 $(如果我做 $(body)。html(),则不会被表示。我怎样才能获取html字符串和更新后的表单值呢?谢谢!
解决方案您可以使用 .attr()函数。
示例:
$(input)。each函数(){ $(this).attr(value,$(this).val()); });在此之后,您可以执行以下操作:
$(body)。html();这应该有效。
I have a form with a textbox like this:
<html> <head> <script type="text/javascript" src="jquery-1.6.2.js"></script> </head> <body> <input type="text" id="myTextBox" /> </body> </html>When I type something in myTextBox, the value is available with $("#myTextBox").val(), but is not represented if i do $("body").html(). How can I grab the html string and the updated form value too? Thanks!
解决方案You can use the .attr() function.
Example:
$("input").each(function(){ $(this).attr("value", $(this).val()); });After this you can do the:
$("body").html();This should work.
更多推荐
jQuery的HTML()不会返回更改的值
发布评论