2

アイテムをクリックせずに選択可能で選択(ハイライト)するにはどうすればよいですか(コードによる)?

選択/ハイライトするボックスのインデックスを付けるように

私はそれらをそのように動的に作成します

<div class="demo">  <ol id="selectable">  </ol></div>

var div = document.getElementById("selectable");
for(i=0; i<list.size; i++)
{    
    // It should look like that
    //<li class="ui-widget-content">Item 1</li>    
    var properties = list[i].getProperties();    
    var aTag = document.createElement("li"); 
    //file name or something as ID    
    aTag.setAttribute('class',"ui-widget-content");    
    aTag.setAttribute('id',i);
    aTag.innerHTML = properties.fileName;
    //file name
    div.appendChild(aTag);
}
4

5 に答える 5

1

$('youritem').trigger('click');仕事をします!簡単な解決策。

于 2011-04-06T20:37:18.443 に答える
1

eq()を使用してインデックスを選択できます。0が最初のアイテムです。

$('item').eq(0).css('background-color','yellow'); //give the first item a yellow background.

http://jsfiddle.net/FKvhG/で実例を確認してください

于 2011-04-06T20:41:26.783 に答える
0

あなたが使用することができますfocus()$('#element').focus();

于 2011-04-06T20:38:41.703 に答える
0

使用できます

$("#id").val("example value")

その値を指定してアイテムを選択します。を使用してインデックスで値を見つけることができます

$("#id").find("option").eq(index).val()

だからそれらをまとめると

$("#id").val($("#id").find("option").eq(index).val());

それはあなたが望むことをします。

于 2011-04-06T20:45:27.550 に答える
0

リストのIDが「ドロップダウン」で、最初の要素を選択する場合は、これが機能します。

eq()関数は、ゼロベースの任意の要素を選択します。

$('#dropdown').eq(0).attr("selected", true);
于 2011-04-06T21:16:22.130 に答える