javascript - 无法从另一个函数中调用一个函数
问题描述
我是 jquery 的新手,并试图调试一个脚本,希望允许用户使用 Shift+Click 选择表的多行并将复选框设置为选中。我在网上找到了一个示例,我正在尝试调试代码,但是我要找到调用函数的位置,但从未输入过该函数。我不确定为什么?
这是脚本:
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 函数的行的输出?
解决方案
推荐阅读
- elasticsearch-rails - rails elasticsearch - 条件索引
- django - django-filter 上的 ModelChoiceFilter
- matlab - 从图像中提取 CMY 颜色分量
- javascript - 我想显示一个页面的数据并使用 chrome 扩展显示到网站的另一个页面中?
- powerbi - 显示正确的目标线
- wget - wget 递归下载所有子目录中的特定文件类型
- scala - Spark:以指定的日期格式读取 csv
- flutter - Flutter 应用程序上的 flutter_dotenv 出现空安全错误
- php - 购买多件商品,但只扣入钱包一次
- python - 使用引用自身的类型进行键入