我已经编写了JavaScript代码。在此警报中显示了多次。
<input type="text" name="grouptype" id="grouptype">
<input type="hidden" id="type_id" name="type_id">
<input type="text" id="type_bal" name="type_bal" onfocus="place1(form.grouptype.id,form.type_id.id)">
function place1(x,y)
{
var place=document.getElementById(x).value;// it hold the value of grouptype
var place_id=document.getElementById(y).value;//it hold the value of type_id
if(place!="" && place_id=="") {
document.getElementById(x).focus();
alert("pl. select the livesearch data");
}
}
不仅我还使用了jQuery代码。以下是代码
//<!-- the following commented code is used to move tab index when we press enter-->
$("input[tabindex],select[tabindex], textarea[tabindex]").each(function () {
$(this).on("keypress", function (e) {
if (e.keyCode === 13)
{
var nextElement = $('[tabindex="' + (this.tabIndex + 1) + '"]');
if (nextElement.length) {
$('[tabindex="' + (this.tabIndex + 1) + '"]').focus();
$('[tabindex="' + (this.tabIndex + 1) + '"]').select();
e.preventDefault();
} else
$('[tabindex="1"]').focus();
}
});
});
上面的代码用于将焦点从一个文本字段移至另一个文本字段,当我在另一个文本字段中保留一个名为place1的焦点函数时,上面的代码给出的焦点函数在没有该文本字段的情况下不会调用该place1函数警报。然后我保持警惕。通过该警报消息,它将被调用3次。为什么?