Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按钮未在输入时提交_Javascript_Html - Fatal编程技术网

Javascript 按钮未在输入时提交

Javascript 按钮未在输入时提交,javascript,html,Javascript,Html,我正在使用搜索表单,我必须单击按钮提交搜索。我想让它在按enter键时进行搜索,但它不起任何作用 <button class="btn btn-default" style="height:34px" type="submit" onclick="Search();"><span class="glyphicon glyphicon-search"></span></button> 这是我的表格 <input type

我正在使用搜索表单,我必须单击按钮提交搜索。我想让它在按enter键时进行搜索,但它不起任何作用

     <button class="btn btn-default" style="height:34px" type="submit" onclick="Search();"><span class="glyphicon glyphicon-search"></span></button>

这是我的表格

    <input type="hidden" name="search_param" value="all" id="search_param">   
              @Html.TextBoxFor(m => m.SearchTrm, new { @class="form-control",id="Searchterm",placeholder="Search for Drug, Disease or Sponsor"})  

            <span class="input-group-btn">
          <button class="btn btn-default" id="btn-default" style="height:34px" type="button" onclick="Search();"><span class="glyphicon glyphicon-search"></span></button>

            </span>

@Html.TextBoxFor(m=>m.SearchTrm,新{@class=“form control”,id=“Searchterm”,placeholder=“搜索药物、疾病或赞助商”})

要使用enter提交表单,按下enter键时必须有表单,并且表单控件必须有焦点(textarea元素除外,enter将在其中插入回车符)。您必须将按钮的单击处理程序移动到表单的提交处理程序(否则它将不会被调用)

默认情况下,表单中的按钮元素是提交按钮

e、 g

函数搜索(表单){
警报('您正在搜索:'+form.searchText.value);
//做事
}

搜索文本:
搜索

它是否在表单标签内?更改type=“submit”for type=“button”并测试它您可以显示您的表单吗?不,我没有使用表单标签。这就是为什么?