Submit a form using anchor element, without javascript

后端 未结 4 1760
傲寒
傲寒 2021-02-19 17:01

How to replace the submit button with a link without using javascript ? is there any way to add the submit attribute to a link ? because the form will not be sent by a simple li

相关标签:
4条回答
  • 2021-02-19 17:41

    Try this:

    CSS

    button {
        background:none!important;
        border:none; 
        padding:0!important;
        /*border is optional*/
        border-bottom:1px solid #444; 
    }
    

    HTML

    <button>your button that looks like a link</button>
    
    0 讨论(0)
  • 2021-02-19 17:52

    This can achieve the same effort and it looks like <a>

    Note: btn btn-link comes from bootstrap

    <button class="btn btn-link" type="submit"><img src="icon.png" /></button>
    
    0 讨论(0)
  • 2021-02-19 17:55

    You can not submit a form using an <a> tag alone. You will need some type of javascript to assist, if you insist on using the <a> tag:

    <a href="#" onclick="$(this).closest('form').submit()">Submit the Form</a>

    or

    <a href="#" onclick="document.getElementById('form-id').submit()">Submit the Form</a>

    or super hack:

    <a href="backendPage.php?param1=yes&param2=no">Submit the Form</a>, then on backendPage.php you can use $_GET requests to process information, and redirect the visitor to the intended page. But that's a horrible idea haha

    0 讨论(0)
  • 2021-02-19 17:56

    There is an another way out. Using this method you can use any element to submit a form. Following is an example:

    <span onclick="$('#submit').trigger('click')" style="cursor:pointer;">
         anything
    </span>
    

    Add a hidden submit button:

     <input style="display:none;" type="submit" id="submit"/>
    

    This will behave exactly as actual submit button.

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