您的位置:首页 > Web前端 > JQuery

jquery项目中一些比较常用的简单方法

2011-09-16 18:59 621 查看
 1:选择器
//这两个都是选择input中被选中的空间,但是在IE中$("#child input:checked")有可能还会选中text控件

$("#child input:checked")

$('#child').find("input[checked=true]")

if (selectradio.length == 0) {

   alert("请选择需要查询的表");

   return;

}
//选择所有checkbox

$("#datatablename :checkbox")

//遍历table下所有为div的节点

$("#table > div")

//遍历selectdatatables下的最后一个子节点

$("#selectdatatables:last-child")

//遍历td下第二个子节点

$('#field #selectdatatables tr td:nth-child(2)')

//遍历id以td开始的节点

$("#selectdatatables td[id^='*td']")

2:控件属性操作
//给属性赋值

$("#child #" + divval).attr("Showcheck", 1);

//显示空间

$("#table").css("display", "block");

//隐藏控件

$("#table").css("display", "none");

//使控件为只读

$('#txtbymachinid').attr("readonly", true);

//控件为没有选中状态

$('#child input:checked').attr("checked", false);

//控件获得焦点

$('#txtbyrodno').focus();

//判断控件的属性

if($("#table").css("display") == "block")

$(this).attr("Showcheck") == 0

3:常用事件及方法
//给select赋值

<select id="parent" style="width: 100%; float: left"></select>

for (var i = 0; i < a.length; i++) {

        $("#parent").append("<option value='" + a[i].parentid + "'>" + a[i].parentname + "</option>");

    }

//当select中显示的值改变时触发的事件

$('#parent').change(function () {

        loadchild($('#parent').val());

    });

//绑定事件,异步会用到

$("#selectdatatables td[id^='*td']").bind("click", function () {

                showfield($(this).text(), $(this).attr("id").replace("*td", ""));

            });

//同步时触发事件

<a href='#' style='text-decoration: none' onclick=oldquery(this,'" + savedname + "')><font color='#757F7F'> 搜索</font></a>

//触发的函数

function fieldDetail(sender, fielddata) {

  $(sender).prev().attr("checked", true); //使当前字段前面的checkbox为选中状态

  $(sender).prev().attr("disabled", "disabled"); //禁用当前字段前面的checkbox

  $(sender).attr("onclick", ""); //禁用当前字段的onclick事件

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息