首先,如果可能的话做您的标记之外,它更容易,所以这样的:
<input type="button" name="test" value="i"
onclick="$('<div></div>').html('test message').dialog(
{title: 'Test Dialog',modal: false, width: 200, height:140, resizable:false});"
/>
是:
<input type="button" name="test" value="i" />
有了这个脚本:
$(function() {
$("input[name='test']").click(function() {
$('<div></div>').html('test message')
.dialog({title: 'Test Dialog',
modal: false,
width: 200,
height:140,
resizable:false});
});
});
然后我们可以添加定位,比如y OU它希望将按钮的右侧,然后使用.offset()
获得按钮的位置,然后将其添加的.outerWidth()
使其出现在右边,就像这样:
$(function() {
$("input[name='test']").click(function() {
var pos = $(this).offset(),
top = pos.top - $(document).scrollTop(); //minus amount scrolled down
$('<div></div>').html('test message')
.dialog({title: 'Test Dialog',
modal: false,
width: 200,
height:140,
position: [pos.left + $(this).width(), top],
resizable:false});
});
});
You can try an example here,它有确切的标记和代码我已经在上面了,并且here's a test version to ensure it works with scrolling。
这是非常好的感谢简明的代码和伟大的链接与例子! 但是,这些按钮将显示在表中。我在ASP中生成HTML(argh!),并且我将拥有未知数量的这些按钮,并且内容将针对该行特定。 方括号表示法允许您将JavaScript放入JSON中吗?如果是的话什么时候执行? 有可能是一种方式,我可以做到这一点 – gordatron 2010-07-07 10:58:42
我已经修改此代码工作内联(ASP生成)非常感谢。 – gordatron 2010-07-07 13:10:14