【发布时间】:2016-08-22 09:27:05
【问题描述】:
我想将我的 form 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 type="text" name="input" value="My Name" />
</form>
我尝试了下面的代码,但它只显示表单元素(不包括表单标签)。
<script>
$(document).ready(function()
{
$('a').on('click', function() {
$("input,select,textarea").each(function() {
if($(this).is("[type='checkbox']") || $(this).is("[type='checkbox']")) {
$(this).attr("checked", $(this).attr("checked"));
}
else {
$(this).attr("value", $(this).val());
}
});
alert($('form').html());
});
});
</script>
上面的代码会提示如下输出,
<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>
【问题讨论】: