我无法使用动态ID调用div

时间:2019-01-11 15:04:39

标签: javascript

我的代码是:

<div id="slider">

这是主要的div:

    <div id="mainNews">
      <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
          <div class="newsInfo" id="news"& element style=" display:block"></div>
        </ItemTemplate>
      </asp:Repeater>            
    </div>             
  </div>    
</div>
<script type="text/javascript" src="js/FirstSlider.js"></script>

JavaScript是:

var sliderTimeoutID;
var element = 1;

function delayedSlider() {
  element == 5 ? element = 1 : element = element;
  element == 1 ? pElement = 4 : pElement = element - 1;
  document.getElementById("news" + pElement).style.display = "none";
  document.getElementById("news" + element).style.display = "block";
  document.getElementById("newsLink" + pElement).className = "newsLinks";
  document.getElementById("newsLink" + element).className = "newsLinks selected";
  sliderTimeoutID = window.setTimeout(delayedSlider, 6000);
  element++;
}

delayedSlider();

我怎么称呼增量编号?

0 个答案:

没有答案