锚定单击“preventDefault”,然后重新打开
下面是问题和代码:
我正在单击已经设置了 href
的锚点。
第 1 步,在锚点 fileMove
单击时,我阻止它触发原始 href
,因为我正在打开一个弹出窗口,供用户单击某些内容并提供一些信息。
$('#fileMove').click(function(e) {
alert($('#fileMove').attr('href'));
e.preventDefault(); //prevent original href
showdevDialog(); //dialog popup call
});
function showdevDialog() {
$('#JQueryFTD_Demo').dialog(); //dialog with div JQueryFTD_Demo
}
// this will be in document.ready
$('#JQueryFTD_Demo').fileTree({
root: 'D:\\Test',
script: '../jqueryFileTree.jsp',
expandSpeed: 1000,
collapseSpeed: 1000,
multiFolder: true,
loadMessage: 'Please Wait While Loading...'
}, function(file) {
//alert(file);
}, function(dir){
moveFileToFolder(dir); //once user selects a folder passing
//it to function
});
该函数隐藏弹出窗口,然后使用文件夹名称构造一个新的 href
,然后绑定单击事件。
function moveFileToFolder(dir) {
$('#JQueryFTD_Demo').hide();
$('#JQueryFTD_Demo').dialog('close');
var _href = $('#fileMove').attr("href");
$('#fileMove').attr("href", _href + '&moveto=' + dir);
alert($('#fileMove').attr('href'));
$('#fileMove').unbind('click').click();
//$('#fileMove').attr('href')
//alert("Inside func.. " + dir);
}
但点击事件再次调用 $('#fileMove').click()
,其中包含 preventDefault
并且没有任何反应。
我该如何解决这个问题?
任何帮助表示赞赏。
Below is problem and code:
I'm clicking on an anchor which has an href
set already.
Step1, upon anchor fileMove
click, I'm preventing it from firing original href
because I'm opening a popup for user to click something and provide some info.
$('#fileMove').click(function(e) {
alert($('#fileMove').attr('href'));
e.preventDefault(); //prevent original href
showdevDialog(); //dialog popup call
});
function showdevDialog() {
$('#JQueryFTD_Demo').dialog(); //dialog with div JQueryFTD_Demo
}
// this will be in document.ready
$('#JQueryFTD_Demo').fileTree({
root: 'D:\\Test',
script: '../jqueryFileTree.jsp',
expandSpeed: 1000,
collapseSpeed: 1000,
multiFolder: true,
loadMessage: 'Please Wait While Loading...'
}, function(file) {
//alert(file);
}, function(dir){
moveFileToFolder(dir); //once user selects a folder passing
//it to function
});
This function hides the popup and then constructs a new href
using the folder name then binds click event.
function moveFileToFolder(dir) {
$('#JQueryFTD_Demo').hide();
$('#JQueryFTD_Demo').dialog('close');
var _href = $('#fileMove').attr("href");
$('#fileMove').attr("href", _href + '&moveto=' + dir);
alert($('#fileMove').attr('href'));
$('#fileMove').unbind('click').click();
//$('#fileMove').attr('href')
//alert("Inside func.. " + dir);
}
But the click event once again calls $('#fileMove').click()
which has preventDefault
and nothing happens.
How do I get around this problem?
Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当对话框可见时,您可以通过执行以下操作有条件地使用
.preventDefault()
:You could use the
.preventDefault()
conditionally only when the dialog is visible by doing something like this: