我希望能够将此处的每个列表项目图像更改为链接选择中的特定图像。
这里是jquery我试图用来改变链接选择中的每个列表图像:
<script type="text/javascript">
var sel = 'url(http://i359.photobucket.com/albums/oo32/41109campbellmichelle/All_zps95vfft3m.png)',
unsel = 'url(http://i359.photobucket.com/albums/oo32/41109campbellmichelle/sims%203%20addict%20resource/allhover_zpscklnx3um.png)';
$('#tab1 li > a').on("click",function (e) {
e.preventDefault();
$link = $(this);
$link.toggleClass("selected");
$link.parent().css('listStyleImage', $link.hasClass("selected")?sel:unsel);
});
var sel = 'url(https://cdn3.iconfinder.com/data/icons/monosign/142/star-128.png)',
unsel = 'url(https://cdn3.iconfinder.com/data/icons/rounded-monosign/142/star-128.png)';
$('#tab2 li > a').on("click",function (e) {
e.preventDefault();
$link = $(this);
$link.toggleClass("selected");
$link.parent().css('listStyleImage', $link.hasClass("selected")?sel:unsel);
});
var sel = 'url(https://cdn3.iconfinder.com/data/icons/monosign/142/star-128.png)',
unsel = 'url(https://cdn3.iconfinder.com/data/icons/rounded-monosign/142/star-128.png)';
$('#tab3 li > a').on("click",function (e) {
e.preventDefault();
$link = $(this);
$link.toggleClass("selected");
$link.parent().css('listStyleImage', $link.hasClass("selected")?sel:unsel);
});
var sel = 'url(https://cdn3.iconfinder.com/data/icons/monosign/142/star-128.png)',
unsel = 'url(https://cdn3.iconfinder.com/data/icons/rounded-monosign/142/star-128.png)';
$('#tab4 li > a').on("click",function (e) {
e.preventDefault();
$link = $(this);
$link.toggleClass("selected");
$link.parent().css('listStyleImage', $link.hasClass("selected")?sel:unsel);
});
var sel = 'url(https://cdn3.iconfinder.com/data/icons/monosign/142/star-128.png)',
unsel = 'url(https://cdn3.iconfinder.com/data/icons/rounded-monosign/142/star-128.png)';
$('#tab5 li > a').on("click",function (e) {
e.preventDefault();
$link = $(this);
$link.toggleClass("selected");
$link.parent().css('listStyleImage', $link.hasClass("selected")?sel:unsel);
});
var sel = 'url(https://cdn3.iconfinder.com/data/icons/monosign/142/star-128.png)',
unsel = 'url(https://cdn3.iconfinder.com/data/icons/rounded-monosign/142/star-128.png)';
$('#tab2 li > a').on("click",function (e) {
e.preventDefault();
$link = $(this);
$link.toggleClass("selected");
$link.parent().css('listStyleImage', $link.hasClass("selected")?sel:unsel);
});
</script>
但如果您查看此页here,它似乎无法更改链接上的列表图片
这是我列表项的代码:
<script type="text/javascript">
$(document).ready(function() {
$(".box-menu a").click(function(event) {
event.preventDefault();
$(this).parent().addClass("current");
$(this).parent().siblings().removeClass("current");
var box = $(this).attr("href");
$(".box-content").not(box).css("display", "none");
$(box).fadeIn();
});
});
</script>
<style>
.boxtextlinks {
padding: 20px;
font-family: Arial, Helvetica, sans-serif;
line-height: 1.5;
font-size: 10px;
}
.boxmenutext {
}
.box-menu {
height: 41px;
float: left;
clear: both;
}
.box-menu li {
height: 41px;
background: -webkit-linear-gradient(#95cffd, #668fe7); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(#95cffd, #668fe7); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(#95cffd, #668fe7); /* For Firefox 3.6 to 15 */
background: linear-gradient(#95cffd, #668fe7); /* Standard syntax (must be last) */
}
.box-menu li {
border-radius: 15px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 0px;
border: 2px solid #002F77;
border-bottom: 0px;
padding: 20px;
width: 80px;
height: 41px;
}
.box-menu li {
height: 41px;
width:80px;
line-height: 42px;
float: left;
margin-right: 4px;
}
li.a {
padding-right:1px;
}
li.current {
border-radius: 15px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 0px;
border: 2px solid #305ea4;
border-bottom: 0px;
padding: 20px;
width: 69px;
height: 41px;
}
.box-menu li.current {
position: relative;
background-color: #71A2D6;
z-index: 5;
margin-top:1px;
}
.box-menu li a {
padding: 6px 11px 0px 10px;
margin:0px 0px 0px -12px;
color: #002f77;
text-decoration: none;
}
.box-menu .current a {
color: #2e7da3;
}
.box {
background-color: #71A2D6;
float: left;
margin-bottom: 20px;
width: auto;}
.box-content {
width: 660px;
padding: 20px;
display: none; }
#box-1 {
display: block;
background-color: #71A2D6;
border:0.15em solid #002f77; }
.main-inner .widget .post-body ul li {
list-style-type: none; }
li.tab2 {
list-style-image: url('http://i359.photobucket.com/albums/oo32/41109campbellmichelle/mentalli_zps9ezx6y2f.png');
list-style-position:inside; }
.tab1 {
list-style-image: url('http://i359.photobucket.com/albums/oo32/41109campbellmichelle/All_zps95vfft3m.png');
list-style-position:inside;
list-style-type:none; }
li.tab3 {
list-style-image: url('http://i359.photobucket.com/albums/oo32/41109campbellmichelle/physical_zpssutwodrw.png'); }
li.tab4 {
list-style-image: url('http://i359.photobucket.com/albums/oo32/41109campbellmichelle/social%202_zpsnwuqkoub.png'); }
li.tab5 {
list-style-image: url('http://i359.photobucket.com/albums/oo32/41109campbellmichelle/other_zpsczsfxiha.png'); }
li.tab2{
margin-top:-1px;
position: relative;
width: 83px; }
li.tab3{
margin-top:-1px;
position: relative;
width:97px;
}
li.tab4{
margin-top:-1px;
position: relative;
width:90px;
}
li.tab5 {
margin-top:-1px;
position: relative;
}
</style>
<div align="center" id="box-container">
<ul class="box-menu">
<li class="current tab1"><a class="tablinks" href="#box-1">All</a></li>
<li class="tab2"><a href="#box-2">Mental</a></li>
<li class="tab3"><a href="#box-3">Physical</a></li>
<li class="tab4"><a href="#box-4">Social</a></li>
<li class="tab5"><a href="#box-5">Other</a></li>
</ul>
<div class="box">
<div id="box-1" class="box-content">
<p class="boxtext">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sit amet purus urna. Proin dictum fringilla enim, sit amet suscipit dolor dictum in. Maecenas porttitor, est et malesuada congue, ligula elit fermentum massa, sit amet porta odio est at velit. Sed nec turpis neque. Fusce at mi felis, sed interdum tortor. Nullam pretium, est at congue mattis, nibh eros pharetra lectus, nec posuere libero dui consectetur arcu. Quisque convallis facilisis fermentum. Nam tincidunt, diam nec dictum mattis, nunc dolor ultrices ipsum, in mattis justo turpis nec ligula. Curabitur a ante mauris. Integer placerat imperdiet diam, facilisis pretium elit mollis pretium. Sed lobortis, eros non egestas suscipit, dui dui euismod enim, ac ultricies arcu risus at tellus. Donec imperdiet congue ligula, quis vulputate mauris ultrices non. Aliquam rhoncus, arcu a bibendum congue, augue risus tincidunt massa, vel vehicula diam dolor eget felis.</p>
</div>
<div id="box-2" class="box-content">
<p class="boxtext">Donec semper dictum sem, quis pretium sem malesuada non. Proin venenatis orci vel nisl porta sollicitudin. Pellentesque sit amet massa et orci malesuada facilisis vel vel lectus. Etiam tristique volutpat auctor. Morbi nec massa eget sem ultricies fermentum id ut ligula. Praesent aliquet adipiscing dictum. Suspendisse dignissim dui tortor. Integer faucibus interdum justo, mattis commodo elit tempor id. Quisque ut orci orci, sit amet mattis nulla. Suspendisse quam diam, feugiat at ullamcorper eget, sagittis sed eros. Proin tortor tellus, pulvinar at imperdiet in, egestas sed nisl. Aenean tempor neque ut felis dignissim ac congue felis viverra. </p>
</div>
<div id="box-3" class="box-content">
<p class="boxtext">Duis egestas fermentum ipsum et commodo. Proin bibendum consectetur elit, hendrerit porta mi dictum eu. Vestibulum adipiscing euismod laoreet. Vivamus lobortis tortor a odio consectetur pulvinar. Proin blandit ornare eros dictum fermentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur laoreet, ante aliquet molestie laoreet, lectus odio fringilla purus, id porttitor erat velit vitae mi. Nullam posuere nunc ut justo sollicitudin interdum. Donec suscipit eros nec leo condimentum fermentum. Nunc quis libero massa. Integer tempus laoreet lectus id interdum. Integer facilisis egestas dui at convallis. Praesent elementum nisl et erat iaculis a blandit ligula mollis. Vestibulum vitae risus dui, nec sagittis arcu. Nullam tortor enim, placerat quis eleifend in, viverra ac lacus. Ut aliquam sapien ut metus hendrerit auctor dapibus justo porta. </p>
</div>
<div id="box-4" class="box-content">
<p class="boxtext">Duis egestas fermentum ipsum et commodo. Proin bibendum consectetur elit, hendrerit porta mi dictum eu. Vestibulum adipiscing euismod laoreet. Vivamus lobortis tortor a odio consectetur pulvinar. Proin blandit ornare eros dictum fermentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur laoreet, ante aliquet molestie laoreet, lectus odio fringilla purus, id porttitor erat velit vitae mi. Nullam posuere nunc ut justo sollicitudin interdum. Donec suscipit eros nec leo condimentum fermentum. Nunc quis libero massa. Integer tempus laoreet lectus id interdum. Integer facilisis egestas dui at convallis. Praesent elementum nisl et erat iaculis a blandit ligula mollis. Vestibulum vitae risus dui, nec sagittis arcu. Nullam tortor enim, placerat quis eleifend in, viverra ac lacus. Ut aliquam sapien ut metus hendrerit auctor dapibus justo porta. </p>
</div>
<div id="box-5" class="box-content">
<p class="boxtext">Proin sollicitudin tincidunt quam, in egestas dui tincidunt non. Maecenas tempus condimentum mi, sed convallis tortor iaculis eu. Cras dui dui, tempor quis tempor vitae, ullamcorper in justo. Integer et lorem diam. Quisque consequat lectus eget urna molestie pharetra. Cras risus lectus, lobortis sit amet imperdiet sit amet, eleifend a erat. Suspendisse vel luctus lectus. Sed ac arcu nisi, sit amet ornare tellus. Pellentesque nec augue a nibh pharetra scelerisque quis sit amet felis. Nullam at enim at lacus pretium iaculis sit amet vel nunc. Praesent sapien felis, tincidunt vitae blandit ut, mattis at diam. Suspendisse ac sapien eget eros venenatis tempor quis id odio. Donec lacus leo, tincidunt eget molestie at, pharetra cursus odio. </p>
</div>
</div>
</div>