[英]How to pass a variable as a function parameter
我有这个函数将类可编辑( td.editable
)的单元格td.editable
为输入字段。 现在,您必须将行传递给函数。 例如: editRow(myRow)
。
所以使用this.parentNode.id
,我得到了行的id。 但是当我将值作为参数传递给editRow
函数时,它什么都不做。
我认为函数认为rowId
是行的实际名称,而不是使用rowId
变量的内容作为行的名称。
function editRow(row) {
$('td.editable',row).each(function() {
$(this).html('<input type="text" value="' + $(this).html() + '" size="10" />');
});
}
/* click on cell with .editable class */
$(".editable").click(function() {
rowId = this.parentNode.id;
editRow(rowId);
});
editRow
不占用行ID,它占用整行(DOM元素本身)。 你只是传递错误的数据。 尝试:
$('.editable').click(function(){
editRow(this.parentNode);
});
鉴于你的功能:
/* click on cell with .editable class */
$(".editable").click(function() {
rowId = this.parentNode.id;
editRow(rowId);
});
您正在将id传递给editRow函数。 所以在editRow中,你可以这样做:
function editRow(row) {
$('#' + row +' td.editable').each(function() {
$(this).html('<input type="text" value="' + $(this).html() + '" size="10" />');
});
}
'#'是jquery id选择器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.