隐藏HTML表单';s“提交”按钮


Hiding an HTML Form's Submit Button

可能重复:
当没有提交按钮时按下回车键时,获取要提交的表格

我正在尝试实现一个具有不可见提交功能的文本输入框。因此,该字段没有附加提交按钮,并且在按下"回车"键时提交。

以下是我希望代码如何运行的示例:

<form method="get" action="<?php bloginfo('home'); ?>/"><p>
<input class="text_input" type="text" value="SEARCH: type &amp; hit Enter" name="s" id="s" onfocus="if 
(this.value == 'SEARCH: type &amp; hit Enter') {this.value = '';}" onblur="if (this.value == '') 
{this.value = 'SEARCH: type &amp; hit Enter';}" />
<input type="hidden" id="searchsubmit" value="" /></p></form>

这是我无法工作的代码:

<p>Have us call you. Input your number:</p>
<input type="text" id="phone" name="phone" maxlength="10" size="10">
<input type="submit" value="Click-to-Call"  onclick="window.open('http://secure.ifbyphone.com/clickto_status.php?click_id=34124&phone_to_call=' + getElementById('phone').value + '&key=asdfjknj3459dj38sdka92bva', 'Clickto' , 'width=200,height=200,toolbar=no,location=no, menubar=no, scrollbars=no, copyhistory=no,resizable=no')">

我曾尝试在"onclick"部分向URL添加带有GET请求的表单属性,但没有成功。

你有什么想法吗?

将此添加到关于ID searchsubmit的css中:

    #searchsubmit
    {    
        visibility: hidden;
    }

该按钮仍将工作,但不可见。如果表单的输入是集中/使用的,则默认情况下输入操作应该有效。


onBlur功能可能会触发你想要的操作。当用户离开输入字段(点击离开)时,onBlur就会发生

您可以尝试使用JQuery:

$(function() {
$('form').each(function() {
    $('input').keypress(function(e) {
        // Enter pressed?
        if(e.which == 10 || e.which == 13) {
            this.form.submit();
        }
    });
    $('input[type=submit]').hide();
});

});

这将触发表单的onSubmit事件,但您可以更改

this.form.submit

对于

$('#phone').blur()

http://api.jquery.com/blur/


尝试添加带有以下内容的javascript脚本块:

   document.getElementsById('phone')[0].onkeydown= function(event)
{
    if (event == undefined)
    {    
        event = window.event;
    }
    if (event.keyCode == 13)
    {
        var js_phone = document.getElementsByName('phone')[0].value;
        window.location = 'myPage.php?phone='+js_phone;
        return false;
    }
};

要隐藏某些内容,可以使用以下代码:

input[type=submit]
{
    display:hidden;
}

input[type=submit]只是一个例子,将其替换为提交按钮的选择器。

希望这能有所帮助。