我想制作一个插件,我将用于一些jQuery AJAX加载表数据.
我有一个正确打印数据的函数,但我如何"挂钩"到特定的URL?
比方说,我希望运行该函数,并且每当运行对/mycustomplugin/myurl.php的请求时都要打印数据?(请注意,url /文件不应该存在)
我没有使用WP插件的经验.
通常情况下,我这样做:
$('#selectRoom a').click( function(e) {
e.preventDefault(); // To prevent the default behavior (following the link or adding # to URL)
// Do some function specific logic here
});
Run Code Online (Sandbox Code Playgroud)
但是,我想这样做,清理(并能够重用):
$('#selectRoom a').click( selectRoom );
function selectRoom () {
e.preventDefault(); // To prevent the default behavior (following the link or adding # to URL)
// Do some function specific logic here
}
Run Code Online (Sandbox Code Playgroud)
问题是,我不能将"e"事件处理程序传递给函数,然后在加载时调用selectRoom()函数.即:
$('#selectRoom a').click( selectRoom(e) );
Run Code Online (Sandbox Code Playgroud)
我能以某种方式修复此问题吗?