单击元素后的load()特定href
Currently I have this JS code:
目前我有这个JS代码:
$('.tile').on('click', function() {
$(".tile").addClass("flipOutX");
setTimeout(function() {
$('.metro .tile-area-darkCrimson').css('backgroundColor','#4c7fb5');
$('.metro .tile-area .user-id').css('backgroundColor','#4c7fb5');
$(".tile-group.main").css({ marginLeft:"-40px", width: "1080px"}).load("company-overview.html");
}, 2000);
});
I also have some HTML <a>
which are buttons and they are all called tile
我也有一些HTML 是按钮,它们都被称为tile
I want to load the specific href
defined in the <a>
as seen here with two of them:
我想加载中定义的特定href,如下所示:
<a class="tile double bg-tile7color animated seven flipInX" data-click="transform">
<div class="tile-content image">
<div class="padding10">
<h2 class="fg-white ntm">Cost</h2>
<p class="fg-white ntm">Pricing and Proposals</p>
</div>
<div class="brand">
<div class="label"></div>
</div>
</div>
</a>
<a class="tile bg-tile8color animated eight flipInX" data-click="transform">
<div class="tile-content icon">
<span>
<img src="images/mthc/referrals.png">
</span>
</div>
<div class="brand">
<div class="text-center padding10 ntp">
<p class="fg-white">Referrals</p></div>
</div>
</a>
How do I change the JS to load whatever they have in their href
's and not what is currently specified in the .load()
part of the function? Currently it's loading company-overview.html
. While that is the case I will also need to make the color changes unique to the buttons so is there any way to integrate this change into the s ?
如何更改JS以加载它们在href中的所有内容而不是当前在函数的.load()部分中指定的内容?目前正在加载company-overview.html。在这种情况下,我还需要对按钮进行独特的颜色更改,那么有没有办法将此更改集成到s中?
2 个解决方案
#1
Simply replace load("company-overview.html")
with .load($(this).attr('href')
to reference the href
attribute of the current/target .tile
being clicked:
只需用.load($(this).attr('href')替换load(“company-overview.html”)以引用当前/目标.tile被点击的href属性:
$('.tile').on('click', function(e) {
e.preventDefault(); // stop the default link click behavior
$(".tile").addClass("flipOutX");
setTimeout(function() {
$('.metro .tile-area-darkCrimson').css('backgroundColor','#4c7fb5');
$('.metro .tile-area .user-id').css('backgroundColor','#4c7fb5');
$(".tile-group.main").css({ marginLeft:"-40px", width: "1080px"}).load($(this).attr('href'));
}, 2000);
});
更多相关文章
- 使用Jquery Ajax更改按钮的颜色(从外部PHP文件接收颜色)
- 在javascript中调用带有双参数()的函数
- Objective-C方法/函数调用。 (来自javascript示例)
- Javascript函数的4种调用方法详解
- JavaScript(ES5)使用保留字作函数名
- 在单选按钮上选中/取消选中,加载/隐藏部分视图
- 将JavaScript函数的值插入SQL Server数据库
- 彻底解决IE8和IE9下ewebeditor上按钮无效的方法
- 轮播图---可以动态添加图片,(封装成一个函数)