Submit an HTML form without having a submit button?

前端 未结 11 1441
攒了一身酷
攒了一身酷 2021-01-01 18:57

Can I submit a html

with
instead of ?

Like this:

         


        
相关标签:
11条回答
  • 2021-01-01 19:43

    For better semantics and graceful degradation, I suggest you do this:

    $(document).ready(function(){
        $('form input[type="submit"]').replaceWith('<div class="submit">Submit the form by clicking this</div>'); // replace submit button with div
    
        $('.submit').live('click', function() {  
            $(this).closest('form').submit();
        });
    });
    

    This way, your form remains usable for clients without JS.

    That being said: Just style your input to look the way you want it to with CSS ;)

    0 讨论(0)
  • 2021-01-01 19:43

    Only by using JavaScript, typically you'd use jQuery and tie the click event of the div to the submit event of the form.

    See: http://api.jquery.com/submit/

    The example there even demonstrates this exact scenario.

    0 讨论(0)
  • 2021-01-01 19:44

    Bind the div click event.

    $("div").click(function(){ $("form#myForm").submit(); });

    0 讨论(0)
  • 2021-01-01 19:45

    why don't you just style a button to look like a regular div? :)

    button{
        border:none;
        background:none;
        padding:0;
        text-align:left; 
    }
    
    0 讨论(0)
  • 2021-01-01 19:47
    $('#myDiv').click(function() {  
        $('#myForm').submit();
    });
    
    0 讨论(0)
提交回复
热议问题