gpt4 book ai didi

javascript - jquery 自动补全多余空格

转载 作者:行者123 更新时间:2023-12-02 20:26:49 25 4
gpt4 key购买 nike

我在 jsp 文件中得到了这个循环

<%    for (int i = 0; i < length; i++)
{
for( int j = 0; j < width; j++)
{
element = MAP_LIST[j][i];
if (element.equals("A"))
{} else if (j == width-1 && i == length-1){
%>
<%=element%><%}
else
{
%>
<%=element%>,<%}
}
}
%>

它使用 jquery 从 Oracle 数据库为我的自动完成文本字段获取 csv 列表

function Mapsheets(type,nomos)
{
$(function() {
var f_data;

$.get('/gaec_web/MapSheets.jsp',{'datasrc-select':datasource, 'type_1': type, 'nomos': nomos}, function(data){
f_data = data.split(',');
$( "#fx_no" ).autocomplete({
source: f_data,
minLength: 2
});
});
});
}

一切都像一个魅力,我输入前 2 个字符,自动完成弹出窗口显示所有内容,当我尝试选择一个值时,我得到的值在尾部有几个 (5) 额外的空格。然后,当它提交时,它会失败,因为它与有问题的 map 名称不匹配。结果看起来像这样

"     320-197"

那么是什么原因造成的呢?例如,如果我单独运行 jsp 页面也能得到正常结果

372-146, 376-146, 372-149, 368-149, 376-149, 380-149, 380-152, 376-152, 372-152, 368-152, 368-155, 376-155, 372-155, 380-155, 368-158, 380-158, 376-158, 372-158

提前致谢

最佳答案

我从来没有使用过jsp,但我猜额外空格的原因是你在for循环中使用的缩进

                   {} else if (j == width-1 && i == length-1){
%>
#there are extra space<%=element%><%}
else
{
%>
<%=element%>,<%}
}

你应该这样放置代码,也许空格会被忽略:

                   {} else if (j == width-1 && i == length-1){
%><%=element%><%}
else
{
%><%=element%>,<%}
}

关于javascript - jquery 自动补全多余空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4715004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com