jquery点击不保留价值?
我遇到这种情况:
$id = 123456;
<a href="<?=$id?>" id="id"></a>
<a href="100" id="count">100</a>
$('#count').live("click", function() {
var votes = $("#count").attr("href");
var id= $("#id").attr("href");
var dataStrings = 'id=' + id+ '&votes=' + votes;
});
如果我执行警报或控制台日志,我只能得到计数值:id=undefined&votes=100
关于问题可能是什么的任何想法吗?
谢谢
编辑:
$id var 是一个 php 变量。如果我查看源代码,我会看到那里有回显的数字:
<a href="123456" id="id"></a>
<a href="100" id="count">100</a>
i have this situation:
$id = 123456;
<a href="<?=$id?>" id="id"></a>
<a href="100" id="count">100</a>
$('#count').live("click", function() {
var votes = $("#count").attr("href");
var id= $("#id").attr("href");
var dataStrings = 'id=' + id+ '&votes=' + votes;
});
if i do a alert or console log i get only the count value: id=undefined&votes=100
any ideas on what the problem might be?
thanks
edit:
the $id var is a php one. and if i view source i see the number being echoed there:
<a href="123456" id="id"></a>
<a href="100" id="count">100</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 html 中可能有另一个元素具有重复的 id="id" 但在您在此处发布的代码之前没有“href”属性。
It is possible that you have another element in your html with a duplicate id="id" but without "href" attribute before the code you posted here.
只是猜测,但我想说部分问题可能是您对 href 的数值的奇怪使用。我会将这些值设为其他属性。
Just a guess, but I'd say part of the problem could be your odd use of numeric values for hrefs. I'd make those values some other attribute.