跪求大牛指点,js取值问题,谢谢

redirggg 2012-06-18 09:37:17
小弟用一个浮出层插件写了一个鼠标移动到会员头像上就弹出相关资料等信息,跟微博等一样,但是不知道怎么取值,如下:

<script>
$("#trigger5").powerFloat({
eventType: "hover",
target: "/member?id=?", //这里id怎么取到会员的uid呢?求指点
targetMode: "ajax"
});
</script>


页面输出的内容为:

<ul><li><a  href="http://localhost/?author=2"><img id="trigger5" src="http://localhost/id=1"/></a></li><li><a  href="http://localhost/wp/?author=1"><img id="trigger5" src="http://localhost/id=2"/></a></li><li><a  href="http://localhost/?author=4"><img id="trigger5" src="http://localhost/id=3"/></a></li></ul>


求大牛指点
...全文
123 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
麟儿 2012-06-19
  • 打赏
  • 举报
回复
<script>
$("#trigger5").powerFloat({
eventType: "hover",
target: "/member?id=" + $(this).attr("src").split("=")[1],
targetMode: "ajax"
});
</script>
001007009 2012-06-19
  • 打赏
  • 举报
回复
试试
mouseenter

http://www.w3school.com.cn/jquery/event_mouseenter.asp
redirggg 2012-06-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

$(dom).mouseover(function(){ // 改成你需要的触发事件
// this.href
....
})
[/Quote]

感谢calmcrime大神指点,我研究了下,改了代码如下:
$(function(){
$(".trigger5").mouseover(function(){
$(this).powerFloat({
target: "/member?uid=" + $(this).attr('rel'),
targetMode: "ajax"
});
});
});

下载可以正常弹出了,可是每次鼠标移动上去,都会发送5-6个请求,如下:

GET http://localhost/member?uid=2 200 OK
GET http://localhost/member?uid=2 200 OK
GET http://localhost/member?uid=2 200 OK
GET http://localhost/member?uid=2 200 OK
GET http://localhost/member?uid=2 200 OK
GET http://localhost/member?uid=2 200 OK
GET http://localhost/member?uid=2 200 OK

redirggg 2012-06-19
  • 打赏
  • 举报
回复
感谢jszoulin指点,这样的话提示:

$(this).attr("src") is undefined
[在此错误处中断]

target: "/member?uid="+ $(this).attr('src').split('=')[1],

redirggg 2012-06-18
  • 打赏
  • 举报
回复
悲剧,看不懂。
001007009 2012-06-18
  • 打赏
  • 举报
回复
$(dom).mouseover(function(){ // 改成你需要的触发事件
// this.href
....
})
redirggg 2012-06-18
  • 打赏
  • 举报
回复
感谢calmcrime指点,但是这样只能取到一个用户的信息,我改了下如下:

<script>
var uid = $(".test").attr('href');
$(".trigger5").powerFloat({
eventType: "hover",
target: "/member?uid="+uid.split('=')[1],
targetMode: "ajax"
});
</script>


这样任意点到一个用户头像上,显示的都是第一个用户的信息,求大牛指点。
001007009 2012-06-18
  • 打赏
  • 举报
回复
var s = 'http://localhost/id=1'; // 获取dom的src
alert( s.split('=')[1] ) // 赋值给变量


target: "/member?id="+s.split('=')[1]

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧