相关疑难解决方法(0)

为什么输入时按Enter键会提交带有单个输入字段的表单

为什么<form>单个<input>字段的a会在用户输入值并按下时重新加载表单Enter,如果?中有2个或更多字段则不会<form>.

我写了一个简单的页面来测试这种古怪.

如果您在第二个表单中输入一个值并按Enter键,您将看到它重新加载传递输入值的页面,就像您调用了一样GET.为什么?我该如何避免呢?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>testFormEnter</title>
</head>
<body>
<form>
  <input type="text" name="partid2" id="partid2" />
  <input type="text" name="partdesc" id="partdesc"  />
</form>
  <p>2 field form works fine</p>
<form>
<input type="text" name="partid" id="partid"  />
</form>
<p>One field form reloads page when you press the Enter key why</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript forms

74
推荐指数
5
解决办法
3万
查看次数

Backbone表单不提交多个输入字段

使用Backbone.js,我有一个表单如下:

<form id="searchBar">
    <input type="search" name="search" id="searchBox" value=""/>
    <input type="text" name="location" id="location" value="City, ST"/>
</form>
Run Code Online (Sandbox Code Playgroud)

并且,处理所述表格的视图如下:

window.FindPlaceView = Backbone.View.extend({

    /*code here*/

    events: {
      "submit form#searchBar" : "processClick"
    },

    processClick: function(e) {
       e.preventDefault();
       console.log("Submitted");
       /*form processing code here*/
    }
});
Run Code Online (Sandbox Code Playgroud)

如果我删除表单中的第二个输入字段,表单将提交输入就好了.一旦我将第二个输入添加回表单,就没有骰子.绑定似乎在那时失去了.

是否有任何理由为什么在表单中有两个字段会在提交事件绑定上抛出一个循环?这看起来像是一个愚蠢的问题,我正撞在墙上.

我已经尝试将输入设置为不同的类型,从中删除所有属性,一切.即使我<input></input>在这里放空,也会打破.

(我应该注意,我这里没有提交按钮,只是尝试提交输入)

想法?

谢谢.

backbone.js

2
推荐指数
1
解决办法
1356
查看次数

标签 统计

backbone.js ×1

forms ×1

html ×1

javascript ×1