I'm trying to save dynamic html so that on a failed validation in asp. mvc the html on the page gets saved and shown after postback.
I add the html dynamically via jquery .append(), add values to the fields, then on click of the submit button the following javascript functions fires:
function GetInnerHTML(node)
{
$("#hdnTblVal").val(node.html());
开发者_高级运维 }
With node being the containing html tag of the dynamic html. After that the content of is retrieved and saved via session variable.
In IE8 even the input values are saved, but in Firefox and Chrome the values are gone.
HTML:
<button id="button">click me</button>
<input type="text" id="hdnTblVal" value="" />
<div id="node">
<span id="first">first</span>
<div id="second">second</div>
</div>
Javascript (with jQuery):
function GetInnerHTML(node) {
$("#hdnTblVal").val(node.html());
}
$(function(){
$('#button').click(function(){
GetInnerHTML($('#node'));
});
});
精彩评论