jQuery的HTML()不会返回更改的值 [英] jquery html() does not return changed values

查看:79
本文介绍了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()不会返回更改的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆