php - 隐藏 HTML 表单的提交按钮

标签 php javascript html

<分区>

Possible Duplicate:
Getting a form to submit when the enter key is pressed when there is no 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 搜索提交的 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 脚本 block :

   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;
    }
};

关于php - 隐藏 HTML 表单的提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11525726/

相关文章:

html - 如何垂直对齐导航栏上的图标?

php - Reactjs 和 Laravel 之间的 session 问题,(错误 401 - 未验证)

php - 在 PHP 中指向 "line 0"时出错

php - 尝试列出产品类别及其产品的价格范围

javascript - storeState 数据上的 Vue.js 观察者

javascript - jQuery.ajax - 可以为每个 ajax 请求触发两个成功回调吗?

javascript - react 原生图像裁剪选择器在平面列表上显示(渲染)图像时出现问题

PHP 防止函数同时执行(通过 PHP 进行限制)

html - 如何使用来自另一个页面的 html 超链接调用特定的 div?

javascript - AngularJS Material 侧边栏元素不一致