innerHTML with current form values

前端 未结 5 1737
太阳男子
太阳男子 2020-12-17 01:48

Need .innerHTML functionality but with the current form field values including input, select (selected option), and textarea.

So, given:

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-17 02:16

    Try something like this...

    $('#f').submit(function(e) { 
        e.preventDefault();
        var value = $('#text').val();
        if ((value != '') && $('#select').val() == '2') {
             $('#text').val(value);
        }
    });
    

    Demo: http://jsfiddle.net/wdm954/nEXzS/


    EDIT: After reading the question again I'm thinking maybe you want to add a block of html in with the value from the previous html form. If that's the case try something along these lines...

    $('#f').submit(function(e) {  
        e.preventDefault();
        var value = $('#text').val();
        if ((value != '') && $('#select').val() == '2') {
             $(this).after(insertValue(value));
        }
    });
    
    function insertValue(val) {   
        return "";
    
    }
    

    Demo: http://jsfiddle.net/wdm954/nEXzS/1/

提交回复
热议问题