我有一个表单,我想将表单的一部分和一些 html 保存到我的数据库中。
<div class="contract">
<label for="Company_PostCode">Postcode</label>
<input class="postcode valid" id="Company_PostCode" name="Company.PostCode" type="text" value="">
<label for="Company_Address">Address</label>
<input class="address valid" id="Company_Address" name="Company.Address" type="text" value="">
// more form elements here
<div class="text">
some text here
</div>
</div>
我做的是
$("#submit-button").on("click", function(e)
{
e.preventDefault();
$(".hidden-field").val($(".contract").html());
if (/* some checks here */)
{
// blah blah
}
else
{
//submit form normally
$("#form-register").submit();
}
});
所以我有一个隐藏字段,用于放置我想要的 html 并将其发布到我的 Controller 。 问题是我表格的值都是空的.. $( ".contract").html() 的所有值都是空的。 有什么想法吗?
最佳答案
我已经在 fiddle 中尝试了你的代码。它工作正常。我也从中获得了值(value)
$( ".contract" ).html();
还可以将此值设置为隐藏元素。
请在 fiddle 中检查这个 http://jsfiddle.net/E6DCS/1/
关于javascript - 将表单的 html 值保存到数据库时值为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16786398/