【发布时间】:2016-08-04 15:08:28
【问题描述】:
我正在使用jquery chosen 实际上我想实现如下图所示的结果,因为它在 sn-p 中显示的结果中运行良好。但是,当我在博客中运行的blog 中上传了相同的代码时,它无法正常工作。我做的一切都正确。下面是我在下面的结果中实现的图像,它在堆栈 sn-p 结果中工作,但不在我的博客中。
$(".chosen-select").chosen();
$(".chosen-select").bind('chosen:hiding_dropdown', function(e, i) {
searched_value = i.chosen.get_search_text();
firstElementOnDropdown = i.chosen.search_results.find('li.active-result').first()
if (firstElementOnDropdown.text().toLowerCase() == searched_value.toLowerCase()) {
firstElementOnDropdown.trigger('mouseup');
var t = i;
setTimeout(function() {
t.chosen.input_blur();
}, 150);
}
});
<link rel="stylesheet" href="http://harvesthq.github.io/chosen/chosen.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script src="http://harvesthq.github.io/chosen/chosen.jquery.js" type="text/javascript"></script>
<div>
<em>Multiple Select with Groups</em><br>
<select data-placeholder="Your Favorite Football Team" style="width:350px;" class="chosen-select" multiple tabindex="6">
<option value=""></option>
<optgroup label="NFC EAST">
<option>Dallas Cowboys</option>
<option>New York Giants</option>
<option>Philadelphia Eagles</option>
<option>Washington Redskins</option>
</optgroup>
</select>
</div>
我在我的博客中实现了下面的代码
<link rel="stylesheet" href="http://harvesthq.github.io/chosen/chosen.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script src="http://harvesthq.github.io/chosen/chosen.jquery.js" type="text/javascript"></script>
<div>
<em>Multiple Select with Groups</em><br />
<select data-placeholder="Your Favorite Football Team" style="width:350px;" class="chosen-select" multiple tabindex="6">
<option value="" />
<optgroup label="NFC EAST">
<option />Dallas Cowboys
<option />New York Giants
<option />Philadelphia Eagles
<option />Washington Redskins
</optgroup>
</select>
</div>
<script type="text/javascript">
$(".chosen-select").chosen();
$(".chosen-select").bind('chosen:hiding_dropdown', function(e, i) {
searched_value = i.chosen.get_search_text();
firstElementOnDropdown = i.chosen.search_results.find('li.active-result').first()
if (firstElementOnDropdown.text().toLowerCase() == searched_value.toLowerCase()) {
firstElementOnDropdown.trigger('mouseup');
var t = i;
setTimeout(function() {
t.chosen.input_blur();
}, 150);
}
});
</script>
当我打开博客时,我发现控制台出现 2 个错误。下面是那个图片
【问题讨论】:
-
这在您的博客中有效,但在控制台中显示错误,如图所示。您只想删除此错误吗?或者还有其他问题。?
-
@FahadKazmi 请阅读全文
-
我尝试了你的博客网站,它在我的桌面上完美运行,因为它在上面的代码片段中运行
-
@FahadKazmi 首先看到这个i.stack.imgur.com/bsOdB.gif 这是在我的博客中工作我想要什么请阅读我发布的整个帖子......当用户键入和触发鼠标事件时我需要实现向上它应该显示它在这里工作的结果我的意思是在stackoverflow sn-p而不是在我的博客中。我希望你得到我
-
@overflowstack9 我回答希望它能起作用。
标签: javascript jquery mouseevent jquery-chosen