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

 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' οnclick=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事件
}

转载于:https://www.cnblogs.com/QiuJL/archive/2011/09/16/4524244.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值