リンクをクリックして選択をトリガーするにはどうすればよいですか?
編集: $("a:contains('item2')").click(); の行が $("a:contains('item2')").click(); オートコンプリート メニューの選択をトリガーしますか?
<!doctype html>
<head>
<title>Test</title>
<script src="jquery-1.6.4.js"></script>
<script src="jquery-ui-1.8.16.js"></script>
</head>
<script>
$(function() {
var menu = $('<div></div>')
.attr('id', 'menu')
.appendTo('body')
.autocomplete({
minLength: 0,
source: ['item1','item2'],
select: function(event, ui){
alert('selected ' + ui.item.label);
}
})
;
$('<button></button>')
.attr('id', 'open')
.button({
label: 'display menu'
})
.click(function() {
menu.focus();
menu.autocomplete("search", "");
})
.appendTo('body')
.height(30)
;
$('<button></button>')
.click(function() {
$("#open").click();
$("a:contains('item2')").click();
})
.appendTo('body')
;
});
</script>
<body>
</body>
</html>