脚本宝典收集整理的这篇文章主要介绍了js实例教程-jquery聚焦文本框与扩展文本框聚焦方法,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
光标聚焦的位置在最前面
代码如下:
<!DOCTYPE htML PubLIC "-//W3C//DTD XHTML 1.0 TransITional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html XMlns="https://www.w3.org/1999/xhtml">
<head>
<title>jquery聚焦文本框 -脚本之家</title>
<script src="https://ajax.GOOGLEapis.COM/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<form action="https://www.baidu.com" id="cse-seArch-box">
<p>
<input type="hidden" name="cx" value="partner-pub-7740261255677392:7064996710" />
<input type="hidden" name="ie" value="UTF-8" />
<!--文本框--><input type="text" name="q" size="25" />
<input type="submit" name="sa" value="搜索" />
</p>
</form>
<script type="text/javascript">
$(document).ready(function () {
$("input[name='q']").focus();
})</script>
</body>
</html>
. 代码如下:
(function($){
$.fn.textFocus=function(v){
VAR range,len,v=v===undefined?0:parseint(v);
this.each(function(){
if($.browser.msie){
range=this.createTextRange(); //文本框创建范围
v===0?range.collapse(false):range.move("character",v); //范围折叠
range.select(); //选中
}else{
len=this.value.length;
v===0?this.setSelectionRange(len,len):this.setSelectionRange(v,v); //dom直接设置选区,然后focus
}
this.focus();
});
return this;
}
})(jQuery)
光标聚焦的位置在最前面
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title>jquery聚焦文本框 -脚本之家</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<form action="https://www.baidu.com" id="cse-search-box">
<p>
<input type="hidden" name="cx" value="partner-pub-7740261255677392:7064996710" />
<input type="hidden" name="ie" value="UTF-8" />
<!--文本框--><input type="text" name="q" size="25" />
<input type="submit" name="sa" value="搜索" />
</p>
</form>
<script type="text/javascript">
$(document).ready(function () {
$("input[name='q']").focus();
})</script>
</body>
</html>
. 代码如下:
(function($){
$.fn.textFocus=function(v){
var range,len,v=v===undefined?0:parseInt(v);
this.each(function(){
if($.browser.msie){
range=this.createTextRange(); //文本框创建范围
v===0?range.collapse(false):range.move("character",v); //范围折叠
range.select(); //选中
}else{
len=this.value.length;
v===0?this.setSelectionRange(len,len):this.setSelectionRange(v,v); //dom直接设置选区,然后focus
}
this.focus();
});
return this;
}
})(jQuery)
觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的js实例教程-jquery聚焦文本框与扩展文本框聚焦方法全部内容,希望文章能够帮你解决js实例教程-jquery聚焦文本框与扩展文本框聚焦方法所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。