Javascript 尝试在没有事件的情况下调用jquery函数
所以把图像和图像变成这样一个链接Javascript 尝试在没有事件的情况下调用jquery函数,javascript,jquery,Javascript,Jquery,所以把图像和图像变成这样一个链接 var imgCell = '<a href="javascript:storeInfo("text","text","ActiveProjects");"><img src="https://cubistmediagroup.sharepoint.com/sites/canvas/PublishingImages/details_ope
var imgCell = '<a href="javascript:storeInfo("text","text","ActiveProjects");"><img src="https://cubistmediagroup.sharepoint.com/sites/canvas/PublishingImages/details_open.png"></a>';
然后在storeInfo函数中我调用这个函数
function controlButton (projectStatus){
$('#'+projectStatus+' tbody td img').live('click', function () {
var theTable = ActiveProjectsTable;
var nTr = this.parentNode.parentNode.parentNode;
if ( this.src.match('details_close') )
{
// This row is already open - close it
this.src = "https://cubistmediagroup.sharepoint.com/sites/canvas/PublishingImages/details_open.png";
theTable.fnClose( nTr );
}
else
{
// Open this row
this.src = "https://cubistmediagroup.sharepoint.com/sites/canvas/PublishingImages/details_close.png";
theTable.fnOpen( nTr, fnFormatDetails(theTable, nTr), 'details' );
}
});
}
所以第一次点击img它调用store info函数,反过来调用controlButton函数。。。然后在control button函数中有jquery代码函数,它需要再次单击。。。我想知道是否有一种方法可以在没有事件的情况下调用jquery函数,这样我就不需要点击两次
一旦调用了controlButton,我怎么能调用jquery函数呢 您的
live
位于功能controlbutton
内,只有在您第一次单击链接时,才会安装eventhandler。然后需要再次单击以执行随“live”指令一起安装的click
处理程序中的代码。您的live
位于功能controlbutton
中。只有当您第一次单击链接时,才会安装eventhandler。然后,它需要第二次单击来执行安装了“live”指令的click
处理程序中的代码。我仍然需要双击来调用“theTable.fnOpen”和close函数。我正在寻找一种方法,可以在一次单击中调用open和close表的单元格。我的朋友,我们需要查看更大的代码示例。另外,我最后编辑了一个小错误,从我最初的post-do开始。我添加了store-info函数,我认为它不起作用,因为代码需要在controlButton函数中单击,而这已经被单击击中了。。。我试图调用这个函数,而不必再次单击。我仍然需要双击来调用“theTable.fnOpen”和close函数。我正在寻找一种方法,可以在一次单击中调用open和close表的单元格。我的朋友,我们需要看到更大的代码示例。另外,我最后编辑了一个小错误,从我最初的post-do开始。我添加了store-info函数,我认为它不起作用,因为代码需要在controlButton函数中单击,而这已经被单击击中了。。。我试着呼叫这个,而不必再次点击。
function controlButton (projectStatus){
// save the function into a variable
var funct = function () {
var theTable = ActiveProjectsTable;
var nTr = this.parentNode.parentNode.parentNode;
if ( this.src.match('details_close') )
{
// This row is already open - close it
this.src = "https://cubistmediagroup.sharepoint.com/sites/canvas/PublishingImages/details_open.png";
theTable.fnClose( nTr );
}
else
{
// Open this row
this.src = "https://cubistmediagroup.sharepoint.com/sites/canvas/PublishingImages/details_close.png";
theTable.fnOpen( nTr, fnFormatDetails(theTable, nTr), 'details' );
}
}
// Retrieve the DOM node
var node = $('#'+projectStatus+' tbody td img');
// Apply the event listener to the node
node.live('click', funct);
// Call the function, with the retrieved node as the call instance('this')
funct.call(node);
}
function controlButton (projectStatus){
// save the function into a variable
var funct = function () {
var theTable = ActiveProjectsTable;
var nTr = this.parentNode.parentNode.parentNode;
if ( this.src.match('details_close') )
{
// This row is already open - close it
this.src = "https://cubistmediagroup.sharepoint.com/sites/canvas/PublishingImages/details_open.png";
theTable.fnClose( nTr );
}
else
{
// Open this row
this.src = "https://cubistmediagroup.sharepoint.com/sites/canvas/PublishingImages/details_close.png";
theTable.fnOpen( nTr, fnFormatDetails(theTable, nTr), 'details' );
}
}
// Retrieve the DOM node
var node = $('#'+projectStatus+' tbody td img');
// Apply the event listener to the node
node.live('click', funct);
// Call the function, with the retrieved node as the call instance('this')
funct.call(node);
}