Art*_*tem 81 jquery input jquery-selectors
我试过了
$(":input:not(input[type=button],input[type=submit],button):visible:first")
Run Code Online (Sandbox Code Playgroud)
但它没有找到任何东西.
我的错是什么?
UPD:我在$(document).load()上执行此操作
<script type="text/javascript">
$(window).load(function () {
var aspForm = $("form#aspnetForm");
var firstInput = $(":input:not(input[type=button],input[type=submit],button):visible:first", aspForm);
firstInput.focus();
});
</script>
Run Code Online (Sandbox Code Playgroud)
在调试中我可以看到firstInput是空的.
UPD2:我在Sharepoint下运行的ASP.NET页面.
到目前为止,我发现对于某些元素,它确实找到了它们(对于固定的元素)而有些则没有.:(
Mot*_*tie 159
为什么不只针对你想要的那些(演示)?
$('form').find('input[type=text],textarea,select').filter(':visible:first');
Run Code Online (Sandbox Code Playgroud)
编辑
或者使用jQuery :输入选择器来过滤表单后代.
$('form').find('*').filter(':input:visible:first');
Run Code Online (Sandbox Code Playgroud)
Pet*_*gne 12
JQuery代码很好.您必须在ready处理程序中执行而不是在窗口加载事件中执行.
<script type="text/javascript">
$(function(){
var aspForm = $("form#aspnetForm");
var firstInput = $(":input:not(input[type=button],input[type=submit],button):visible:first", aspForm);
firstInput.focus();
});
</script>
Run Code Online (Sandbox Code Playgroud)
更新
我尝试了Karim79的例子(感谢这个例子)并且它工作正常:http://jsfiddle.net/2sMfU/
小智 6
这是我对上述内容的总结,对我来说非常适合.谢谢(你的)信息!
<script language='javascript' type='text/javascript'>
$(document).ready(function () {
var firstInput = $('form').find('input[type=text],input[type=password],input[type=radio],input[type=checkbox],textarea,select').filter(':visible:first');
if (firstInput != null) {
firstInput.focus();
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
117901 次 |
| 最近记录: |