如何通过jQuery获取表单html(),包括<;表格></表格>;标签?
我想将我的表单html内容显示到一个文本区域中,该文本区域允许用户通过用户界面编辑表单元素。这是我的表格如何通过jQuery获取表单html(),包括<;表格></表格>;标签?,html,forms,tags,Html,Forms,Tags,我想将我的表单html内容显示到一个文本区域中,该文本区域允许用户通过用户界面编辑表单元素。这是我的表格 <form name="myform" action="abc.php"> <input type="radio" name="radio1" value="1" checked> <input type="radio" name="radio2" value="2"><br><br> <input t
<form name="myform" action="abc.php">
<input type="radio" name="radio1" value="1" checked>
<input type="radio" name="radio2" value="2"><br><br>
<input type="text" name="input" value="My Name" />
</form>
我尝试了下面的代码,但它只显示表单元素(不包括表单标记)
$(文档).ready(函数()
{
$('a')。在('click',function(){
$(“输入,选择,文本区域”)。每个(函数(){
if($(this.is(“[type='checkbox']”)是(“[type='checkbox']”)是(“[type='checkbox']”)是($this.is(“[type='checkbox'])){
$(this.attr(“选中”),$(this.attr(“选中”);
}
否则{
$(this.attr(“value”,$(this.val());
}
});
警报($('form').html());
});
});
上面的代码警告如下输出
<input type="radio" name="radio1" value="1" checked>
<input type="radio" name="radio2" value="2"><br><br>
<input type="text" name="input" value="My Name" />
<form name="myform" action="abc.php">
<input type="radio" name="radio1" value="1" checked>
<input type="radio" name="radio2" value="2"><br><br>
<input type="text" name="input" value="My Name" />
</form>
但我需要一个如下的输出
<input type="radio" name="radio1" value="1" checked>
<input type="radio" name="radio2" value="2"><br><br>
<input type="text" name="input" value="My Name" />
<form name="myform" action="abc.php">
<input type="radio" name="radio1" value="1" checked>
<input type="radio" name="radio2" value="2"><br><br>
<input type="text" name="input" value="My Name" />
</form>
我希望您可以将这些函数用于form$(“form”).clone().appendTo(“body”)代码>其他使用
<div id='formdiv1'>
<form name="myform" action="abc.php">
<input type="radio" name="radio1" value="1" checked>
<input type="radio" name="radio2" value="2"><br><br>
<input type="text" name="input" value="My Name" />
</form>
</div>
alert($('#formdiv1').html());
警报($('#formdiv1').html());
我希望您可以将这些函数用于form$(“form”).clone().appendTo(“body”)代码>其他使用
<div id='formdiv1'>
<form name="myform" action="abc.php">
<input type="radio" name="radio1" value="1" checked>
<input type="radio" name="radio2" value="2"><br><br>
<input type="text" name="input" value="My Name" />
</form>
</div>
alert($('#formdiv1').html());
警报($('#formdiv1').html());