我是jquery的新手,正在尝试调试脚本,该脚本有望允许用户使用Shift + Click选择表的多行并将复选框设置为selected。我在网上找到了一个示例,并尝试调试代码,但是我要在调用函数的行中排队,但是从未输入该函数。我不确定为什么吗?
这是脚本:
j$ = jQuery.noConflict();
j$(document).ready(function() {
if(j$) {
//alert('Jquery loaded successfully...');
}
console.log(j$('input[id$=btnSearch]'));
j$('input[id$=btnSearch]').click(function(){
console.log(j$('[id$=searchTable] > tbody tr'));
var trs = j$('[id$=searchTable] > tbody tr');
j$('tr').on('click', function(myEvent){
//call the RowClick function on click event
RowClick(j$(this),false,trs,myEvent)
})
});
});
//declare variable to store the most recently clicked row
var lastSelectedRow;
// disable text selection
document.onselectstart = function() {
return false;
}
function RowClick(currentrow, lock, rows, myEvent) {
console.log('******************************************* we are inside the RowClick function');
console.log(currentrow);
console.log(lock);
console.log(rows);
console.log(myEvent);
//if control is held down, toggle the row
if (myEvent.ctrlKey) {
toggleRow(currentrow);
}
//if there are no buttons held down...
if (myEvent.button === 0) {
//if neither control or shift are held down...
if (!myEvent.ctrlKey && !myEvent.shiftKey) {
//clear selection
clearAll(rows);
//toggle clicked row
toggleRow(currentrow);
}
//if shift is held down...
if (myEvent.shiftKey) {
console.log('************************************** we are in the shift key branch');
console.log(currentrow);
console.log(currentrow.index());
console.log(rows);
console.log('************************************** we are calling the toggleRow function');
toggleRow(currentrow);
console.log('************************************** we have called the toggleRow function');
//pass the indexes of the last selected row and currently selected row along with all rows
selectRowsBetweenIndexes([lastSelectedRow.index(), currentrow.index()], rows)
}
}
}
function toggleRow(row) {
console.log('******************************* we are inside the toggleRow function');
console.log(row);
if (!row.hasClass('header-row')){
console.log('****************************** we are inside the row does not have the header-row class');
lastSelectedRow = row.toggleClass('selected');
}
}
function selectRowsBetweenIndexes(indexes,rows) {
//sort the indexes in ascending order
indexes.sort(function(a, b) {
return a - b;
});
//for every row starting at the first index, until the second index...
for (var i = indexes[0]; i <= indexes[1]; i++) {
//select the row
j$(rows[i+1]).addClass('selected');
}
}
function clearAll(rows) {
j$('.selected').removeClass('selected');
}
我到这一行:
console.log('************************************** we are calling the toggleRow function');
下一行输出是这一行:
console.log('************************************** we have called the toggleRow function');
从不输入toggleRow函数。我是jquery新手,不清楚我是否错误地调用了该函数?或者,为什么为什么看不到显示我已进入toggleRow函数的行的输出?