新窗口对象和链接单击之间的竞争条件
A race condition between new window object and link click
我遇到了创建新窗口对象和单击链接之间的竞争条件。新窗口是一个名为AjaxUpload的插件,其输入需要一个具有唯一ID的链接元素。请注意,AjaxUploads会打开一个新的文件选择窗口。
该页面需要许多链接,这些链接会带来具有唯一ID的文件选择窗口。因此,为了简化场景,计划是将一个新的ID附加到单击的链接,创建窗口对象,模拟鼠标单击以打开窗口,销毁ID,并对其他链接执行相同的操作。
然而,当在窗口对象加载完成之前执行模拟单击时,就会出现问题,导致代码仅在链接单击两次时才起作用。
这是代码:
$(document).ready(function() {
// The link is an anchor element with icon camera class
// that will be attached with a new ID called wall-image-upload
// which will destroyed after the window is brought up
$( "a.icon.camera" ).click(function(e) {
// Exit the function when wall-image-upload
// id is created to avoid infinite loop
if ($('#wall-image-upload').length!==0) {
return;
}
// Create the ID
e.target.setAttribute("id", "wall-image-upload");
// Create AjaxUpload object to handle the
// image attachment where it looks up link
// with wall-image-upload ID
var uploader = new window.AjaxUpload(
'wall-image-upload',
{ action: 'wall_upload/{{$nickname}}',
name: 'userfile',
onSubmit: function(file,ext) { $('#profile-rotator').show(); },
onComplete: function(file,response) {
addeditortext(response);
$('#profile-rotator').hide();
}
}
);
// Simulate click on the element, this doesn't effect on
// anything unfortunately
$('#wall-image-upload').trigger("click");
// Destroy the id
$('#wall-image-upload').prop("id",null);
});
});
我应该在哪里以及如何放置
$('#wall-image-upload').trigger("click");
要正确执行吗?
这个问题无关紧要。没有出现竞赛情况。问题是,无论是什么原因,模拟点击都不会打开窗口。这个问题已经结束。
相关文章:
- 使用javascript单击同一按钮,在两种样式之间更改css值
- 如何通过单击点之间的样条曲线来选择样条曲线中的序列
- 在 JavaScript 中单击函数时两个日期类型输入之间的差异的代码
- 镜像滚动效果打开.在两个容器之间单击
- 单击.之间具有特定名称的链接的JS.<>标签.我应该使用 window.find(string).click()、
- 每次单击时在2个类之间切换
- JQuery ajax在2个按钮之间切换's类具有2次单击事件,但无法更改按钮的值
- 单击时,如何使用 toggleClass 在我的 $('p') 标签上在华氏度和摄氏度之间切换
- 单击时在参数之间切换的最佳方式
- j查询复选框的更改和单击事件之间的差异
- 单击时在文本之间插入图像节点
- .click() 和实际单击按钮之间的区别?(javascript/jQuery)
- 在两个或多个 UL 列表之间切换,如果单击一个列表,则其他列表会自动以初始状态返回,就像从未单击过一样
- 单击按钮时在角度过滤器之间切换
- 单击按钮时,将光标放在文本区域中的 2 点之间
- 我如何使用 javascript 或 jquery 在单击时在任何 css 属性之间切换
- 取消类之间特定元素的单击
- jQuery 检测鼠标是否在 mouseenter 和mouseleave之间单击
- 每次单击时在文本之间切换
- 根据单击的链接在4个css类之间切换