【发布时间】:2017-01-21 13:10:27
【问题描述】:
我正在尝试为点击事件中的不同元素设置相同的 URL:
$(document).ready(function() {
var realStateBtn = $('#real-estate-center').parent();
var link = $('#real-estate-center > .linkwidth');
var realStateClass = $('.real-estate-center');
var bankOwnedProps = $('#bank-owned-properties > span');
var findYourHomesValue = $('#find-your-homes-value > span');
realStateBtn.css('zIndex', 9999);
realStateBtn.click(function() {
window.location.href='https://realestatecenter.bankofamerica.com/';
});
link.click(function() {
window.location.href="https://realestatecenter.bankofamerica.com/";
});
realStateClass.click(function() {
window.location.href="https://realestatecenter.bankofamerica.com/";
});
findYourHomesValue.click(function() {
window.location.href="http://realestatecenter.bankofamerica.com/tools/marketvalue.aspx";
});
bankOwnedProps.click(function() {
window.location.href="http://realestatecenter.bankofamerica.com/";
});
});
我在一些不同的函数中调用这个方法:
window.location.href="http://realestatecenter.bankofamerica.com/";
这是我要避免的,我只想使用一次。
有什么建议吗?
【问题讨论】:
-
在要更改的元素上放一个通用类?
标签: javascript jquery