我需要一个函数来发送警报,然后在文本字段留空时返回。我的带有文本字段的js列表是:
var filterList = [{name: "filterStartTime", type: "date", label: "Alguskuupäev"},
{name: "filterEndTime", type: "date", label: "Lõppkuupäev"},
{name: "filterDoctorCode", type: "text", label: "Dokumendi koostaja arstikood", upper:true},
{name: "filterDoctorSpecialityCode", type: "select", label: "Dokumendi koostaja erialakood", upper:true},
{name: "filterDocIdAndOid", type: "sub", label: "Dokumendi identifikaator", sub: [
{name: "filterDocIdOid", type: "text", label: "OID", size: 35, noCheckbox: true},
{name: "filterDocId", type: "text", label: "ID", noCheckbox: true}],
noCheckbox: false
},
{name: "filterCompanyCode", type: "text", label: "Koostaja asutuse registrikood"},
{name: "filterDocumentType", type: "select", label: "Dokumendi tüüp"}
];
我调用它们的jsp文件是:
String filterDoctorCode = request.getParameter("filterDoctorCode");
if(filterDoctorCode != null) filterDoctorCode = filterDoctorCode.trim();
String filterDoctorSpecialityCode = request.getParameter("filterDoctorSpecialityCode");
if(filterDoctorSpecialityCode != null) filterDoctorSpecialityCode = filterDoctorSpecialityCode.trim();
String filterDocIdOid = request.getParameter("filterDocIdOid");
if(filterDocIdOid != null) filterDocIdOid = filterDocIdOid.trim();
String filterDocId = request.getParameter("filterDocId");
if(filterDocId != null) filterDocId = filterDocId.trim();
String filterCompanyCode = request.getParameter("filterCompanyCode");
if(filterCompanyCode != null) filterCompanyCode = filterCompanyCode.trim();
if(statusCode == null) statusCode = "deliveredResponse";
dlPatDocs.setProcedure(statusCode, filterDoctorCode, filterStartTime, filterEndTime, filterDocIdOid, filterDocId, filterCompanyCode, filterDoctorSpecialityCode);
sendId = dlPatDocs.send();
所以我知道我很难理解我的描述,但我希望有人理解并可以提供帮助。
在JS中,我认为我需要在这里添加警报: else if(filterList[i].type == "text"){
if (!filterList[i].size) filterList[i].size = 20;
filterInnerHtml += "<input type=\"text\" id=\"" + filterList[i].name + "_input\" ";
if (filterList[i].upper) filterInnerHtml += " onchange='javascript:fieldValToUpperCase(this);' "
filterInnerHtml += " class=\"txt_left\" value=\"\" maxlength=\""+ filterList[i].size + "\" size=\""+ filterList[i].size + "\" />";
}
但我不确定......
抱歉,我忘了提到列表是在第三个文件中调用的:
<td>
<!-- Will be built by JS in FilterBank.js#addFilterBank() -->
<div id = "filtripank"></div>
</td>
</tr>
<tr>
<td>
<img src="images/progress.gif" alt="" border="0" id="progressIndicator" style="display:none" />
<input type="button" class="button" value="Saada päring" onClick="javascript:startDocumentListUpdate()" id="updateButton" />
</td>
所以当我点击&#34; updateButton&#34;它检查文本值是否为空,如果是,则发回消息并且不执行onClick&#34; javascript:startDocumentListUpdate()&#34; .....希望它有意义
答案 0 :(得分:0)
inout test field:
<input type="text" name="checking" id="checking" onblur="checkTextField(this);" />
用于检查的javascript为空:
function checkTextField(field) {
if (field.value == '') {
alert("Field is empty");
}
}
答案 1 :(得分:0)
这是一个检查空文本字段的实时示例:
var filterList = [{name: "filterStartTime", type: "date", label: "Alguskuupäev"},
{name: "filterEndTime", type: "date", label: "Lõppkuupäev"},
{name: "filterDoctorCode", type: "text", label: "Dokumendi koostaja arstikood", upper:true},
{name: "filterDoctorSpecialityCode", type: "select", label: "Dokumendi koostaja erialakood", upper:true},
{name: "filterDocIdAndOid", type: "sub", label: "Dokumendi identifikaator", sub: [
{name: "filterDocIdOid", type: "text", label: "OID", size: 35, noCheckbox: true},
{name: "filterDocId", type: "text", label: "ID", noCheckbox: true}],
noCheckbox: false
},
{name: "filterCompanyCode", type: "text", label: "Koostaja asutuse registrikood"},
{name: "filterDocumentType", type: "select", label: "Dokumendi tüüp"}
];
function checkEmpty(list) {
var i;
for (i in list) {
if (list[i].type == "text") {
var name = list[i].name;
if ($("input[name=" + name + "]").val() == "") {
alert(name + " is empty !");
}
}
if (list[i].sub) {
checkEmpty(list[i].sub);
}
}
}
$(function () {
$("button").click(function () {
checkEmpty(filterList);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
filterDoctorCode: <input type="text" name="filterDoctorCode"/><br/>
filterDocIdOid: <input type="text" name="filterDocIdOid"/><br/>
filterDocId: <input type="text" name="filterDocId"/><br/>
filterCompanyCode: <input type="text" name="filterCompanyCode"/><br/>
<button>check empty</button>