请帮帮我!
如何在jquery中选择以编程方式选择的项目?
我想要打电话mousedown event manullay
<div id="Explorer">
<!--items-->
</div>
<input type="button" title="Select" click="Select()"/>
<script>
$("#Explorer").selectable();
function Select() {
//i know following code is incorrect
$("#Explorer").children().eq(4).select();
}
</script>
答案 0 :(得分:0)
代码中有几处错误:
1-使用select()
是错误的。
2-不要重新声明select
名称
$(function() {
$("#Explorer").selectable();
});
function my_select() {
$("#Explorer").find('.item').eq(4).addClass('ui-selected');
}
&#13;
#Explorer .ui-selecting {
background: #FECA40;
}
#Explorer .ui-selected {
background: #F39814;
color: white;
}
#Explorer {
list-style-type: none;
margin: 0;
padding: 0;
width: 60%;
}
#Explorer p {
margin: 3px;
padding: 0.4em;
font-size: 1.4em;
height: 18px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" rel="stylesheet" />
<div id="Explorer">
<p class="item">Item 1</p>
<p class="item">Item 2</p>
<p class="item">Item 3</p>
<p class="item">Item 4</p>
<p class="item">Item 5</p>
<p class="item">Item 6</p>
<p class="item">Item 7</p>
</div>
<input type="button" title="Select" onclick="my_select()" value="select" />
&#13;