當前位置:編程學習大全網 - 網站源碼 - 如何用jquery獲得option的索引值index?

如何用jquery獲得option的索引值index?

需要準備的材料分別有:電腦、html編輯器、瀏覽器。

1、首先,打開html編輯器,新建html文件,例如:index.html,並引入jquery。

2、在index.html中的<script>標簽,輸入jquery代碼:

$('select option').each(function (i) {

if ($(this).attr('selected')) {

$('body').append(i);

}

});

3、瀏覽器運行index.html頁面,此時用jquery獲取到了option的索引值被打印了出來。

  • 上一篇:VB中如何把控件變成透明的?
  • 下一篇:python 抽獎
  • copyright 2024編程學習大全網