我遇到了window.location.href的一些问题。 在我的网站上,我使用AngularJS框架。 我有一个带有以下代码的表格:
<table id="MAND">
<tbody id="hoveren">
<tr ng-repeat="artist in artists | filter:name">
<td class="user-name"><img id="{{artist.div}}" style="vertical-align: middle;" src="{{artist.img}}"></td>
<td class="user-email" style="vertical-align: middle;">{{artist.name}}</td>
<td class="user-phone" style="vertical-align: middle;">{{artist.description}}</td>
<td class="user-phone" style="vertical-align: middle;">{{artist.country}}</td>
</tr>
</tbody>
</table>
所以你可以看到,<div> 标签为图片提供了一个 divname。
然后在 jQuery 中,我调用以下函数:
$("#crunch").click(function() {
window.location.href = "http://example.com/new_url";
});
在这个案例中,{{"artist.div"}}等于crunch,这就是为什么出现了#crunch的原因。
为什么这不起作用?
我点击它但是没有任何反应。
这是什么愚蠢的错误吗?
谢谢!
顺便说一下,如果你想知道,我的angularjs部分:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
angular.module('App', [])
.controller('Controller', function($scope){
$scope.artists = [
{
"name": "Crunchyroll",
"country": "All countries except Japan",
"img":"images/crunchy.png",
"description":"You can set it to everything you want!",
"div":"crunch"
},
{
"name": "Rhapsody",
"country": "US only, be at the right spot",
"img":"images/rhap.png",
"description":"You can set it to everything you want!"
},
{
"name": "Febreze",
"country": "US only",
"img":"images/feb.jpg",
"description":"You can set it to everything you want!"
},
{
"name": "Kellogs Froot Loops",
"country": "US only",
"img":"images/kel.jpg",
"description":"You can set it to everything you want!"
},
{
"name": "Pure Asia Garcinia Weight Loss",
"country": "US, AU, CA, UK and NZ only",
"img":"images/bottle.png",
"description":"You can set it to everything you want!"
},
{
"name": "Free Computer",
"img":"images/pc.png",
"description":"You can set it to everything you want!"
},
{
"name": "whateveee",
"country": "All countries except Japan",
"img":"images/crunchy.png",
"description":"You can set it to everything you want!",
"div":"crunch"
}
];
});
不要跑,我不知道如何把它放进去。
谢谢!