Submitting a form by pressing enter without a submit button

前端 未结 20 1549
你的背包
你的背包 2020-11-22 06:46

Well I am trying to submit a form by pressing enter but not displaying a submit button. I don\'t want to get into JavaScript if possible since I want everything to work on a

相关标签:
20条回答
  • 2020-11-22 07:02

    Have you tried this ?

    <input type="submit" style="visibility: hidden;" />
    

    Since most browsers understand visibility:hidden and it doesn't really work like display:none, I'm guessing that it should be fine, though. Haven't really tested it myself, so CMIIW.

    0 讨论(0)
  • 2020-11-22 07:02

    I added it to a function on document ready. If there is no submit button on the form (all of my Jquery Dialog Forms don't have submit buttons), append it.

    $(document).ready(function (){
        addHiddenSubmitButtonsSoICanHitEnter();
    });
    function addHiddenSubmitButtonsSoICanHitEnter(){
        var hiddenSubmit = "<input type='submit' style='position: absolute; left: -9999px; width: 1px; height: 1px;' tabindex='-1'/>";
        $("form").each(function(i,el){
            if($(this).find(":submit").length==0)
                $(this).append(hiddenSubmit);
        });
    }
    
    0 讨论(0)
  • 2020-11-22 07:04

    Just set the hidden attribute to true:

    <form name="loginBox" target="#here" method="post">
        <input name="username" type="text" /><br />
        <input name="password" type="password" />
        <input type="submit" hidden="true" />
    </form>
    
    0 讨论(0)
  • 2020-11-22 07:05

    You could try also this

    <INPUT TYPE="image" SRC="0piximage.gif" HEIGHT="0" WIDTH="0" BORDER="0">
    

    You could include an image with width/height = 0 px

    0 讨论(0)
  • 2020-11-22 07:06
    <input type="submit" style="display:none;"/>
    

    This works fine and it is the most explicit version of what you're trying to achieve.

    Note that there is a difference between display:none and visibility:hidden for other form elements.

    0 讨论(0)
  • 2020-11-22 07:08

    Try:

    <input type="submit" style="position: absolute; left: -9999px"/>
    

    That will push the button waaay to the left, out of the screen. The nice thing with this is, you'd get graceful degradation when CSS is disabled.

    Update - Workaround for IE7

    As suggested by Bryan Downing + with tabindex to prevent tab reach this button (by Ates Goral):

    <input type="submit" 
           style="position: absolute; left: -9999px; width: 1px; height: 1px;"
           tabindex="-1" />
    
    0 讨论(0)
提交回复
热议问题