jquery html() does not return changed values

前端 未结 4 1139
梦毁少年i
梦毁少年i 2020-12-03 03:20

I have a form with a textbox like this:



    


        
相关标签:
4条回答
  • 2020-12-03 03:45
    $('[type=text], textarea').each(function(){ this.defaultValue = this.value; });
    $('[type=checkbox], [type=radio]').each(function(){ this.defaultChecked = this.checked; });
    $('select option').each(function(){ this.defaultSelected = this.selected; });
    

    then

    $("body").html()
    
    0 讨论(0)
  • 2020-12-03 03:49

    Well there is one most simpler way of doing this, by employing the live function on the input.

    $(document).ready(function() {
    
     var checker = false;
        $("input").live("change", function() {
            checker = (this.defaultValue !== this.value);
            if (checker)
                this.defaultValue = this.value;
        });
    });
    
    0 讨论(0)
  • 2020-12-03 03:52
    $('input').each(function(){
      $(this).attr('data-value-input', $(this).val());
    });
    

    and after that you can get your html

    var bodyHtml = $('body').html().toString().replace('data-value-input', 'value');
    

    and that is it.

    0 讨论(0)
  • 2020-12-03 04:06

    You can use the .attr() function.

    Example:

    $("input").each(function(){
        $(this).attr("value", $(this).val());
    });
    

    After this you can do the:

        $("body").html();
    

    This should work.

    0 讨论(0)
提交回复
热议问题