div class =" list-show"数据行动="选项托盘"> - >当点击下拉框时,它应该将显示添加为块,但它总是在firefox中添加隐藏。但它在chrome中运行良好。我认为"存在一些问题。 $(window).click(function(e){ 。碱$ optionTray.hide(); });"码。我无法解决它。
//这是编译为javascript的Typescript文件
private rootSelectionString: string = ".js-multiselectDropdown";
private actionButtonSelectionString: string = "*[data-action='colex']";
private optionTraySelectionString: string = "*[data-action='option-tray']";
private checkboxTraySelectionString: string = "*[data-action='checkbox-tray']";
private selectedClass= "selected";
private $rootElement: JQuery;
private $optionTray: JQuery;
private $checkboxTray: JQuery;
private $actionButton: JQuery;
private dataId;
private listLength;
private searchCheckedBoxes;
private checkBoxes;
constructor(el) {
var base = this;
base.$rootElement = $(el);
base.$optionTray = base.$rootElement.find(base.optionTraySelectionString).eq(0);
base.$checkboxTray = base.$rootElement.find(base.checkboxTraySelectionString).eq(0);
base.$actionButton = base.$rootElement.find(base.actionButtonSelectionString).eq(0);
base.optionPopulation();
base.attachEvent();
base.initialValueCapture();
}
private attachEvent() {
var base = this;
if(base.$rootElement.length!==0) {
base.$optionTray.hide();
base.$actionButton.click(function(){
event.stopPropagation();
base.$optionTray.toggle();
});
$(window).click(function(e) {
base.$optionTray.hide();
});
$(".list-show").click(function(event) {
event.stopPropagation();
});
base.$optionTray.find('li[data-id]').click(function() {
base.$actionButton.find('span').html("");
$(this).toggleClass(base.selectedClass);
if($(this).hasClass(base.selectedClass)){
base.$checkboxTray.find('[data-id="'+$(this).data('id')+'"]').attr('checked','1');
}
else {
base.$checkboxTray.find('[data-id="'+$(this).data('id')+'"]').removeAttr('checked');
}
base.searchCheckedBoxes = base.$rootElement.find('input:checked').map(function() {
return $(this).val();
});
var dataArr=[];
$.each(base.searchCheckedBoxes.get(),function(i,v) {
dataArr.push(v);
});
if(dataArr.length!==0) {
base.$actionButton.find('span').append(dataArr+",");
}
else {
base.$actionButton.find('span').html("Choose Tag");
}
});
}
}
//这是显示下拉菜单的HTML代码
<div class="js-multiselectDropdown" style="float:left">
<div class="action-btn " data-action="colex"><span>Choose Tag</span></div>
<div class="list-show" data-action="option-tray">
<ul></ul>
</div>
<div data-action="checkbox-tray" class="hidden">
<input type="checkbox" value="O"/>O</br>
<input type="checkbox" value="G" checked/>G</br>
<input type="checkbox" value="E"/>E</br>
<input type="checkbox" value="N" checked/>N</br>
</div>
</div>
答案 0 :(得分:0)
看来,下面的函数没有通过事件属性
base.$actionButton.click(function(){
event.stopPropagation();
base.$optionTray.toggle();
});
似乎没有把事件放在函数()上,我没有设置TypeScript编译器,但是如果你只是将事件添加到function()定义中,你应该好好去