设置包含readonly,disabled属性的input标签按tab键时不获取焦点的方法

记录一下今天遇到的一个问题:
在布置页面时有些input框不可输入而且有些是动态设置的,现在有个需求,不可输入的input框按tab键时不停留,如果一个个去加就太慢了,写个共通方法吧。

/**
 * 设置包含readonly,disabled属性的input标签按tab键时不获取焦点的方法
 */
function setTabindex(){
    
    
	$("input").each(function(){
    
    
		if($(this).attr("readonly")=="readonly" || $(this).attr("disabled")==true){
    
    
			$(this).attr("tabindex","-1");
		}
	})
}

然后在有需要的页面进行调用即刻

// 引入util.js
<script type="text/javascript" src="../js/util.js"></script>

// 调用方法
$(document).ready(function(){  
	setTabindex();
});

好了 到这来就结束了。

参考:
https://blog.csdn.net/weixin_41845576/article/details/79715770
https://blog.csdn.net/gnail_oug/article/details/46940389

Guess you like

Origin blog.csdn.net/c15162/article/details/118082917