select对象如何使用selectedIndex属性?

  • 原创
  • |
  • 浏览:2971
  • |
  • 更新:

select对象selectedIndex属性是获取或设置下拉列表中被选项目的索引号,返回整数

select对象如何使用selectedIndex属性?

工具/原料

  • 1.编辑器:notepad++ v.7.7.1
  • 2.浏览器:百度浏览器8.7.5000.4983

方法/步骤

  1. 1

    创建一个名称为select__selectedIndex    的html文件 

    select对象如何使用selectedIndex属性?
  2. 1
    该信息未经许可获取自百度经验
  3. 2

    添加一个 select 下拉列表对象引入js文件 设置id为 my_select_id_selectedIndex

    select对象如何使用selectedIndex属性?
  4. 3

    添加一个button按钮,在点击事件中加入自定义函数 为my_select_selectedIndex

     

    添加一p标签,设置id 为 show_select_selectedIndex

    select对象如何使用selectedIndex属性?
  5. 4

    在javascript中创建一个自定义函数   my_select_selectedIndex

    select对象如何使用selectedIndex属性?
  6. 5

    在自定义函数中获取select下拉列表对象。用 selectedIndex 属性获取选中的下拉 列表选项的索引值,将获取的结果添加到p标签中显示

    select对象如何使用selectedIndex属性?
  7. 6

    在浏览器中打开文件 select__selectedIndex,在浏览器端选选择一个选项再点击button查看效果

    select对象如何使用selectedIndex属性?
    END

总结

  1. 1

    1.首先获取select对象

    2.用selectedIndex来获取选中项目的索引值

    3.在浏览器端选选择一个选项

    4.再点击button来获取索引值

    END

注意事项

  • 先选择一个下拉列表的选项,在点击button查看选中的索引号
经验内容仅供参考,如果您需解决具体问题(尤其法律、医学等领域),建议您详细咨询相关领域专业人士。
作者声明:本篇经验系本人依照真实经历原创,未经许可,谢绝转载。
展开阅读全部