我在 Adobe Business Catalyst 站点上创建的页面中实现一些简单的 jQuery 时遇到了一些麻烦。我在下面包含了相关的 HTML:
<div class="banner-main">
<div class="banner-top">
<section class="banner">
<div class="catProdAttributeItem">
<select id="banner-pic">
<option value="30644690">Red </option>
<option value="30791632">Purple </option>
</select>
</div>
</section>
</div>
</div>
以下 HTML 是创建页面时生成的内容:
<div class="banner-main">
<div class="banner-top">
<section class="banner">
<div class="catProdAttributeItem">
<div class="ddOutOfVision" id="banner-pic_msddHolder" style="height: 0px; overflow: hidden; position: absolute;">
<select id="banner-pic" tabindex="-1">
<option value="30644690">Red </option>
<option value="30791632">Purple </option>
</select>
</div>
<div class="dd ddcommon borderRadius" id="banner-pic_msdd" tabindex="0" style="width: 422px;">
<div class="ddTitle borderRadiusTp">
<span class="divider"></span>
<span class="ddArrow arrowoff"></span>
<span class="ddTitleText " id="banner-pic_title">
<span class="ddlabel">Purple</span>
<span class="description" style="display: none;"></span>
</span>
</div>
<input id="banner-pic_titleText" type="text" autocomplete="off" class="text shadow borderRadius" style="display: none;">
<div class="ddChild ddchild_ border shadow" id="banner-pic_child" style="z-index: 1; position: absolute; visibility: visible; height: 59px; top: 40px; display: none;">
<ul>
<li class="enabled _msddli_ selected">
<span class="ddlabel">Red</span>
<div class="clear"></div>
</li>
<li class="enabled _msddli_">
<span class="ddlabel">Purple</span>
<div class="clear"></div>
</li>
</ul>
</div>
</div>
</div>
</section>
</div>
</div>
如您所见,msDropDown正在更改选择下拉菜单并将其变成无序列表。.banner-main div 有一个背景图片,我想根据下拉选择更改该图片。下面的 jQuery 是我第一次,最直接的尝试,但没有奏效:
<script type="text/javascript">
var pictureList = [
'url(images/red.jpg)',
'url(images/purple.jpg)', ];
$(document).ready(function(){
$('li.enabled._msddli_').click(function() {
alert('clicked');
var val = $('li.enabled._msddli_.selected').index();
$('.banner-main').css('background-image', pictureList[val]);
});
});
</script>
从那以后,我又尝试了几件事,但无论出于何种原因,msDropDown 生成的任何元素都没有触发 .click() 事件。我很困惑,所以任何帮助将不胜感激!