开发者

<input> value not being saved when using .html() to add html code to <input type="hidden"> in FF, Chrome

开发者 https://www.devze.com 2023-03-07 10:28 出处:网络
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'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'));
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消