下拉框select,Jquery的data()方法,JavaScript join() 方法用于把数组中的所有元素放入一个字符串

1、在dataGrid中创建select:

    //创建提前天数单元格
    function renderDay(e) {
        var rec = e.record;
        var tmp = []
        for(var i=1,l=8;i<l;i++){
            if(rec.remindDay==i){
                tmp.push('<option value="'+i+'" selected>'+i+'</option>');
            }else{
                tmp.push('<option value="'+i+'" >'+i+'</option>');
            }
        }
        var str='<select class="selectOPT" data-kk="'+rec.remindId+'">'+tmp.join("")+'</select>';//join()方法把数组转化为字符串
        return str;
    }

2、下拉框值改变时触发的事件

 $(document).on("change",".selectOPT",function(e){
            var $this = $(this);
            debugger;
//            console.info($this.data("id"));
            console.info($this.data("kk"));
            console.info($this.attr("data-kk"));
            $(this).val(5);
        })

3、jQuery 数据 - jQuery.data() 方法
data() 方法向被选元素附加数据,或者从被选元素获取数据。

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#btn1").click(function(){
    $("div").data("greeting", "Hello World");
  });
  $("#btn2").click(function(){
    alert($("div").data("greeting"));
  });
});
</script>
</head>
<body>
<button id="btn1">把数据添加到 div 元素</button><br />
<button id="btn2">获取已添加到 div 元素的数据</button>
<div></div>
</body>
</html>
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  testObj=new Object();
  testObj.greetingMorn="Good Morning!";
  testObj.greetingEve="Good Evening!";
  $("#btn1").click(function(){
    $("div").data(testObj);
  });
  $("#btn2").click(function(){
    alert($("div").data("greetingEve"));
  });
});
</script>
</head>
<body>
<button id="btn1">把数据添加到 div 元素</button><br />
<button id="btn2">获取已添加到 div 元素的数据</button>
<div></div>
</body>
</html>

4、jquery中用on来绑定事件,经常的写法有

1)样式
$(document).on('click','.classname',function(){});
$('.classname').on('click',function(){});
(2)id
$(document).on('click','#idname',function(){});
$('#idname').on('click',function(){});

==理解==
(document).ondocument (‘#idname’).on是把事件绑定到了元素上

区别:$(‘#idname’).on 当页面动态刷新时,新加载的该id元素便没有事件绑定到上面了。 而第一个还可以让事件生效。例如:

$(document).on("click","#dynamicEle", function(e){
alert("some thing");
});

当dynamicEle动态刷新后事件还在。如果用onclick绑定则事件不存在了,因为onclick只在页面onload的时候执行一次,刷新后的dynamicEle已经不是原来的dynamicEle了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值