作者:婷婷爱BB | 来源:互联网 | 2023-09-06 14:42
写了段东西,在chrome和火狐下都可以跑,但在IE下不生效求高手指点。
(function($) {
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| $.extend($.fn, {
trTOCheck: function (setting) {
$.fn.trTOCheck.default = {
renderTo: $(document.table),
}
//找到table
$.extend({},$.fn.trTOCheck.default,setting);
setting.renderTo = (typeof setting.renderTo == 'string' ? $(setting.renderTo) : setting.renderTo);
//找到tbody
var tb= setting.renderTo.find('tbody');
//禁止input的冒泡
$(tb).on("DOMNodeInserted",function () {
$(tb).find("input").on("click",function(event) {
event = event ? event : window.event;
event.cancelBubble = true;
event.stopPropagation();
});
//点击TR时选中input
$(tb).find("tr").on("click", function(){
var _cb = $(this).find("input:checkbox");
var _radio = $(this).find("input:radio");
if( _cb.length> 0){
if(_cb.attr("checked")){
_cb.removeAttr("checked")
}else{
_cb.attr("checked","checked")
}
}
if(_radio.length > 0){
if(_radio.attr("checked")){
_radio.removeAttr("checked")
}else{
_radio.attr("checked","checked")
}
}
})
})
}
}) |
})(jQuery);