我正在尝试获取信息(ajax)并将其显示在弹出窗口(jquery或等效物)中,但我的问题是我的页面中有多个div标签。
<div id="1"><a href="#">mouseover detail for id #1</a></div>
<div id="2"><a href="#">mouseover detail for id #2</a></div>
<div id="3"><a href="#">mouseover detail for id #3</a></div>
OR
<div><a href="get.php?id=1">mouseover detail for id #1</a></div>
<div><a href="get.php?id=2">mouseover detail for id #2</a></div>
<div><a href="get.php?id=3">mouseover detail for id #3</a></div>
感谢您的帮助。
答案 0 :(得分:0)
为div添加一个类,让你编写类似..
的通用代码<div class="someclass" data-id="1"><a href="#">mouseover detail for id #1</a></div>
<div class="someclass" data-id="2"><a href="#">mouseover detail for id #2</a></div>
<div class="someclass" data-id="3"><a href="#">mouseover detail for id #3</a></div>
然后写代码......
var SM=null;
$('.someclass').hover(function(){
var data=$(this).attr('data-id');
if(data==null) return;
var url='get.php?'+data;
$.get(url,function(response){
// taken from simplemodal samples page.
SM = new SimpleModal({"btn_ok":"Alert button"});
SM.show({
"title":"Title",
"contents":response
});
},function(){
// not sure about the close method.
// probably SM.close() or SM.hide(). If you have worked on it, add it here.
});
});