jQuery的HTML()不会返回更改的值

编程入门 行业动态 更新时间:2024-10-27 02:18:39
本文介绍了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()不会返回更改的值

本文发布于:2023-10-25 22:28:55,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jQuery   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!