提取要在 jquery 函数中使用的链接 ID
Extracting a link id to use within a jquery function
all.
我知道这相对简单,但我对javascript的经验不足。背景是我正在尝试在同一页面上使用具有单独模态的简单模态。这种事情之前已经解释过(http://code.google.com/p/simplemodal/issues/detail?id=32),但我不太了解 this.id,并且代码不起作用。
我认为我的术语在这里甚至不正确,但是选择器没有正确检索我的链接想法并使用"#osx_"字符串解析它。使用警报后,我意识到了这一点(实际上是几个小时后)。
$('a.osx').click(function () {
$('#osx_' + this.id).modal();
});
我知道我的 HTML 设置正确,如果我将"#osx_newsletter"硬编码到两个位置,它就可以正常工作。这显然会杀死我需要的动态 id。
这是代码。有人可以让我知道我在这里做错了什么吗?我将不胜感激!谢谢!
/*
* SimpleModal OSX Style Modal Dialog
* http://simplemodal.com
*
* Copyright (c) 2013 Eric Martin - http://ericmmartin.com
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*/
jQuery(function ($) {
var OSX = {
container: null,
init: function () {
$("a.osx").click(function (e) {
e.preventDefault();
alert('#osx_'+$(this).attr('id'));
$('#osx_' + 'donate').modal({
overlayId: 'osx-overlay',
containerId: 'osx-container',
closeHTML: null,
minHeight: 80,
opacity: 65,
position: ['0',],
overlayClose: true,
onOpen: OSX.open,
onClose: OSX.close
});
});
},
open: function (d) {
var self = this;
self.container = d.container[0];
d.overlay.fadeIn('slow', function () {
$('#osx_' + 'donate', self.container).show();
var title = $("#osx-modal-title", self.container);
title.show();
d.container.slideDown('slow', function () {
setTimeout(function () {
var h = $("#osx-modal-data", self.container).height()
+ title.height()
+ 20; // padding
d.container.animate(
{height: h},
200,
function () {
$("div.close", self.container).show();
$("#osx-modal-data", self.container).show();
}
);
}, 300);
});
})
},
close: function (d) {
var self = this; // this = SimpleModal object
d.container.animate(
{top:"-" + (d.container.height() + 20)},
500,
function () {
self.close(); // or $.modal.close();
}
);
}
};
OSX.init();
});
你可以试试这种方式:
$('a.osx').click(function () {
$('[id="osx_' + this.id+'"]').modal();
});
相关文章:
- 根据选项卡内部的文本链接中的哈希ID动态选择jqueryUI选项卡
- 如何进行AJAX调用,使其仅在我单击包含在特定类中的链接时触发;id”;父元素的
- 通过单击链接(兄弟姐妹?)从无线电输入中获取id
- 通过id查找元素并附加链接
- url中没有id的内部链接
- 如何绑定多个具有相同敲除功能、传递不同ID的链接
- 修复Javascript代码以将文本中的所有Youtube链接转换为Youtube ID功能
- 如何从链接中检索 ID
- 使用 JS 捕获链接 ID,然后定向到链接
- 如何在另一个html文件中获取超链接ID
- jQuery编辑链接id
- 链接id使用jquery传递值到表单
- 使用javascript替换基于查询字符串的自定义链接id
- 基于它's调用超链接id定制弹出窗口
- 文档.getElementById用于链接id
- 从jQuery选项卡搜索脚本中删除链接ID元素
- 从jQuery选项卡脚本的链接ID中删除元素
- 简单的JavaScript将数组链接ID附加到html文档中
- 提取要在 jquery 函数中使用的链接 ID
- 使用javascript获取被点击的html链接id