gpt4 book ai didi

javascript - 尝试在没有事件的情况下调用 jquery 函数

转载 作者:行者123 更新时间:2023-11-28 02:38:22 24 4
gpt4 key购买 nike

因此将图像变成这样的链接

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 函数,该函数将获取“text”、“text”和“activeprojects”并将它们设置为全局变量,以便多个 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 函数,这样我就不需要两次点击。

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

最佳答案

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);
}

关于javascript - 尝试在没有事件的情况下调用 jquery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13069816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com