最近开发中遇到的问题

1. BootStrap模态框回车刷新的问题

最近开发一个需求,需要在BootStrap的模态框中实现回车键查询功能,每次按下回车键的时候,页面就会刷新,点击查询按钮则没有问题.
Google了一下发现很多人遇到了这个问题.

How to avoid refreshing the page in a bootstrap modal?

Keep a Modal Window open after form submission.

也有人在Github提了Issue:

Modal closes on Enter key press when there’s a form

问题的原因可能是: form表单提交的默认行为导致的. 按下Enter后,form表单可能会被提交.具体的原因暂时还没有时间研究.以后有时间再研究.

Press Enter to Submit 背后的那些事

提出的解决方案有以下几种:

  • 把输入控件type='submit'改成其他的类型:
1
<button class="btn" id="signin_button">Sign in</button>
  • 阻止表单提交的默认行为:
1
2
3
$( "form" ).submit(function( event ) {
event.preventDefault();
});

我使用第二种方案解决了这个问题.

2. easyui datagrid 问题

今天遇到一个问题,easyui datagrid 初始化的时候,添加width: 'auto',table就不见了.
代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
$('#table').datagrid({
idField: 'ypmlid',
//width: 'auto',
height: 250,
singleSelect: false,
pagination: false,//是否分页
fit: false,
fitColumns: false,
columns: [[
{ field: 'ck', width: '110', checkbox: true }
]]
});

注释掉 width: 'auto' 问题就解决了.

太坑了,搞一晚上也不知道为啥…………..