自定义选择框的表索引问题

tabindex issue with custom select box

本文关键字:索引 问题 选择 自定义      更新时间:2023-09-26

我从谷歌找到了这个脚本。但它不能与tabindex一起工作。你能帮我修一下这个吗?

这里是jsfield链接

js代码段:-

$('select').each(function () {
    // Cache the number of options
    var $this = $(this),
        numberOfOptions = $(this).children('option').length;
    // Hides the select element
    $this.addClass('s-hidden');
    // Wrap the select element in a div
    $this.wrap('<div class="select"></div>');
    // Insert a styled div to sit over the top of the hidden select element
    $this.after('<div class="styledSelect"></div>');
    // Cache the styled div
    var $styledSelect = $this.next('div.styledSelect');
    // Show the first select option in the styled div
    $styledSelect.text($this.children('option').eq(0).text());
    // Insert an unordered list after the styled div and also cache the list
    var $list = $('<ul />', {
        'class': 'options'
    }).insertAfter($styledSelect);

需要使用jQuery动态设置tabindex

//Adds tabindex dynamically 
$this.attr("tabindex", "0");
http://jsfiddle.net/elitownsend/BB3JK/4733/