<a class="some" id="1" href="/s/1/2">link 1</a>
<a class="some" id="2" href="/s/2/3">link 1</a>
<script>
$(document).ready(function() {
$('.some').click(function() {
var id = this.id;
var link = $(this).css('href');
alert(id);
alert(link);
return false;
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
当我点击链接时,我得到了正确的ID,但是"未定义"链接.有什么问题,我该如何解决?
更改
var link = $(this).css('href');
Run Code Online (Sandbox Code Playgroud)
至
var link = $(this).attr('href');
Run Code Online (Sandbox Code Playgroud)
.css()用于获取/设置CSS属性,.attr()用于获取/设置元素的属性.
| 归档时间: |
|
| 查看次数: |
297 次 |
| 最近记录: |