我想在搜索完成后保留我的输入字段数据
i want to retain my input field data even after search is done
@RequestMapping(value= "/search")
public String personList(@ModelAttribute("employee") Employee e,ModelMap map,@RequestParam("drop") String value)
{
/*System.out.println("In Controller " + e.getEmployeeName() +" "+ value);*/
map.put("drop",value);
map.put("employee",e);
map.put("employeeList", employeeService.employeeList(e.getEmployeeName(),value));
return "ViewPage";
}
以上是我的控制器代码
<form:form action="search.html" modelAttribute="employee" method="POST">
<select id="ViewByName" class ="dropdown" name= "drop">
<!-- <option value="r">Select....</option> -->
<option value="s">Starts With</option>
<option value="c">Consist Of</option>
<option value="e">Ends With</option>
</select>
<div id="search-inner">
<td>
<form:input path="employeeName" type="text" name="search" maxlength="30" id="searchfield" title="searchfield" value="type the name of employee to search..." class = "search"
onfocus="if (this.value=='type the name of employee to search...') this.value=''"
onblur="if (this.value == '') this.value ='type the name of employee to search...'"/>
<input type="submit" name="Search" value="Name Search" title="Search" />
</td>
</div>
</form:form>
以上是我的JSP页面代码。我的问题是当我从下拉列表中选择某个选项并在搜索后根据下拉值输入文本输入搜索时,我输入字段转到默认文本,但我想将其保留在搜索结果页面中。
您可以使用请求参数,如下所示:
@RequestMapping(value= "/search")
public String personList(@ModelAttribute("employee") Employee e,ModelMap map,@RequestParam("drop") String value,HttpServetRequest request)
{
request.setparameter("searchdata",drop);
/*System.out.println("In Controller " + e.getEmployeeName() +" "+ value);*/
map.put("drop",value);
map.put("employee",e);
map.put("employeeList",employeeService.employeeList(e.getEmployeeName(),value));
return "ViewPage";
}
在 jsp 页面上,您可以获得如下值
<%= request.getParameter("searchdata") %>
记录后编辑
解决方案只是将搜索输入字段上的值="转换为占位符="。
值覆盖了来自绑定的信息。
请按如下方式更改代码:(jsp)
<form:input path="employeeName" type="text" name="search" maxlength="30" id="searchfield" title="searchfield" class = "search" value="${not empty employee.employeeName? employee.employeeName : 'type the name of employee to search'}" />
并添加 jQuery:
$(document).ready(function() {
$("#searchfield").focus(function(){
if (this.value == "type the name of employee to search")
{
this.value = "";
$(this).css('color','#000000');
}
});
$("#searchfield").blur(function(){
if (this.value == "")
{
this.value = "type the name of employee to search";
$(this).css('color','#a9a9a9');
}
});});
在 jsp 中而不是 value="键入要搜索的员工的姓名..."占位符="键入要搜索的员工的姓名..."应该使用,然后它工作正常,即使在搜索完成后也会保留输入字段数据。感谢您的所有建议。
<form:input path="employeeName" type="text" name="search" maxlength="30" id="searchfield" title="searchfield" placeholder="type the name of employee to search..." class = "search"
onfocus="if (this.value=='type the name of employee to search...') this.value=''"
onblur="if (this.value == '') this.value ='type the name of employee to search...'"/>
相关文章:
- Flash Uploadify在调用我的MVC控制器时没有保留会话/授权
- 开放图层导出为 KML 并保留我的地图样式
- 我的iframe赢了't在用javascript更改src值后,保留它的src值
- 即使在重新加载 javascript 后,我如何保留值的值
- 我试图在流星中吐出我正在保留的数组的列表;不显示
- 为什么我的 JavaScript 哈希带有保留字“toString”作为显示 NaN 的键
- 如何在点击 javascript 警报时保留我的 Firefox 首选项
- self 在 JavaScript 中不是一个保留字 - 所以它是如何在没有在我的脚本中定义的的情况下使用它的
- 我想在搜索完成后保留我的输入字段数据
- 如何保留我的下拉选择
- 我可以保留一个文档片段的引用吗
- "class是一个保留的标识符“;我的javascript出了什么问题
- 每次使用时,我的数组也会保留以前的值
- 我的代码是否有任何错误,不允许在关闭应用程序后在移动浏览器上保留cookie
- PHP中的第一个下拉框不保留我的选择
- 如何使用localStorage保留我的输入
- 每次在我的表中只保留一个可见的部分
- 我的函数没有保留其变量
- 在与父页相同的窗口中打开GridView行,同时保留我的值
- 如何在单击提交后保留我的HTML页面