如何使用jQuery获取生成的HTML表单 [英] how to get generated html form with jquery

查看:66
本文介绍了如何使用jQuery获取生成的HTML表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这张表格

<form id="myForm">
<input name="foo" value=""  />
<input name="bar" value=""  />
... other dynamic input generated by jquery
</form>

如何获取所有的html,包括"foo"和"bar"的值以及其他输入值?

How do I get all the html, including the values ​​of "foo" and "bar" and other input values?

我不需要这些值,但是所有生成的html都包括用户输入的值.

I do not need the values, but all the generated html including the values ​​entered by users.

$ ('#myform').html()

不带用户输入的值就返回表单的html

returns the html of the form WITHOUT the values ​​entered by users

推荐答案

您可以手动设置值属性,如下所示:

You can manually set the value attributes like this:

$('#myForm input').each(function(){ 
    $(this).attr('value', $(this).val());
});
console.log($('#myForm').html());

工作小提琴: http://jsfiddle.net/7g6CP/1/

请谨慎操作,但是,您可能会面临一些安全问题.

Be careful what you do with this however, you might be opening yourself up to some security concerns.

这篇关于如何使用jQuery获取生成的HTML表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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