可能是重复问题:
在没有提交按钮的情况下,使表单在按下回车键时提交
我正在尝试实现一个带有不可见提交功能的文本输入框。因此,该字段没有附加提交按钮,并且在按下“enter”键时提交。
这是我想要代码如何运作的示例:
<form method="get" action="<?php bloginfo('home'); ?>/"><p>
<input class="text_input" type="text" value="SEARCH: type & hit Enter" name="s" id="s" onfocus="if
(this.value == 'SEARCH: type & hit Enter') {this.value = '';}" onblur="if (this.value == '')
{this.value = 'SEARCH: type & 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')">
我尝试使用GET请求将表单属性添加到“onclick”部分的URL中,但无效。
有什么想法可以使其正常工作吗?
onsubmit=""
来放置 JavaScript 代码,这样当表单提交时它就会被执行。 - MrGlass