Efe*_*Efe 9 javascript jquery jquery-ui
我之前问过这个问题,但我认为我没有正确解释我想要完成的任务.
我的网站上有多个链接,我想在jquery ui模式对话框小部件中打开链接中的内容.
我正在尝试使用'this'来引用用户动态选择的链接.我在这做错了什么?
我正在使用的代码如下:
<a href="index.cs.asp?Process=comments&id=1" id="test">comment #1</a>
<a href="index.cs.asp?Process=comments&id=2" id="test">comment #2</a>
<a href="index.cs.asp?Process=comments&id=3" id="test">comment #3</a>
<div id="somediv"></div>
<script type="text/javascript">
$(document).ready(function() {
$("#somediv").load(this.getTrigger().attr("href")).dialog({
autoOpen: false,
width: 400,
modal: true
});
$("#test").click(function(){$( "#somediv" ).dialog( "open" );});
});
</script>
Run Code Online (Sandbox Code Playgroud)
CC.*_*CC. 16
一对更改:将ID更改为Class并使用IFrame.
<a href="http://wikipedia.com/" class="test">comment #1</a><br>
<a href="http://ebay.com/" class="test">comment #2</a><br>
<a href="http://ask.com/" class="test" >comment #3</a><br>
<div id="somediv" title="this is a dialog" style="display:none;">
<iframe id="thedialog" width="350" height="350"></iframe>
</div>
<script>
$(document).ready(function () {
$(".test").click(function () {
$("#thedialog").attr('src', $(this).attr("href"));
$("#somediv").dialog({
width: 400,
height: 450,
modal: true,
close: function () {
$("#thedialog").attr('src', "about:blank");
}
});
return false;
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
如果你想引入HTML而不是IFrame,你将不得不使用Ajax(XMLHttpRequest),如下所示:http://jsfiddle.net/qp7NP/1/
| 归档时间: |
|
| 查看次数: |
43075 次 |
| 最近记录: |