1

所以把和图像变成这样的链接

var imgCell = '<a href="javascript:storeInfo(&quot;text&quot;,&quot;text&quot;,&quot;ActiveProjects&quot;);"><img src="https://cubistmediagroup.sharepoint.com/sites/canvas/PublishingImages/details_open.png"></a>';

这将调用 storeInfo 函数,该函数将获取“文本”“文本”和“活动项目”并将它们设置为全局变量,以便它们可以被多个 javascript 函数使用......

function storeInfo (filePath, webAddress, projectStatus){
theFilePath = filePath;
theWebAddress = webAddress;
controlButton(projectStatus);}

然后在 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 函数......然后在控制按钮函数中有 jquery 代码函数,需要再次点击......我想知道是否有一种在没有事件的情况下调用 jquery 函数的方法,这样我就不需要点击 2 次。

调用 controlButton 后如何调用 jquery 函数?

4

1 回答 1

1
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);
}
于 2012-10-25T13:42:20.537 回答