[英]Navigate to element in Different tab of same page using focus() function
I am doing validation of entire form which is spread into different section where each section is a nav-tab
, when i fill the entire form and cursor is in the last section, on clicking the save button if there is a validation mismatch of textbox in first section(first nav-tab) and if i want the user to be focused to the failed textbox document.getElementById(ID).focus()
is not navigating to the element where validation has failed. 我正在验证整个表格,该表格会分散到不同的部分,其中每个部分都是nav-tab
,当我填写整个表单并且光标位于最后一个部分时,如果存在文本框的验证不匹配的情况,请单击保存按钮第一部分(第一个导航选项卡),如果我希望用户将注意力集中在失败的文本框document.getElementById(ID).focus()
则不会导航到验证失败的元素。
How to achieve the above functionality?? 如何实现以上功能?
function validate()
{
var valid = true;
var alphaFilter = /^[A-z]{0,}$/;
if (!(alphaFilter.test($('#fieldId').val()))
{
if(valid){$('#fieldId').focus();}
$('#fieldId').css("border-color", "#e84e40");
valid = false ;
}
--- each field has its own if condition
return valid;
}
validate function is called inside the submit function for further processing and valid variable is used to focus first invalid entry in the form. validate函数在Submit函数内部被调用以进行进一步处理,而有效变量则用于将表单中的第一个无效条目作为焦点。
I would make a param to take in selectors to make this more usable. 我将加入选择器以使其更有用。
Something like this.. 像这样
function switchtab (){
$("#tab1").removeClass("active");
$("#tab2").addClass("active");
$("#tabpanel1").removeClass("active");
$("#tabpanel2").addClass("active");
//should be good to focus now
$(selector).focus();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.