ここに jsfiddle があります: http://jsfiddle.net/JQnUs/4/
HTML:
<div class="problem-select">
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input type="hidden" value="1" />
</div>
<div class="overlapping-div">
</div>
<div class="hover-here">Hover here</div>
<input class="other-input" type="text" />
CSS:
.problem-select {
position: absolute;
top: 0px;
left: 0px;
z-index: 0;
}
.overlapping-div {
position: absolute;
top: 0px;
left: 0px;
width: 100px;
height: 100px;
background-color: red;
z-index: 100;
display: none;
}
.hover-here {
position: absolute;
right: 70px;
top: 0px;
border: 1px solid black;
height: 100px;
width: 100px;
}
.other-input {
position: absolute;
top: 200px;
left: 0px;
}
jQuery (1.8.2 を使用):
jQuery(document).ready(function() {
jQuery(".hover-here").hover(function(){ showDiv(); }, function(){ hideDiv(); });
//Used in potential solution 7...
//jQuery("select").change(function(){ jQuery(this).siblings('input').val(jQuery(this).val()); });
});
function showDiv() {
//Potential solution number 1... (does't work in chrome or safari)
//jQuery('select').blur();
//Potential solution number 2... (leaves lines on top of the red div)
//jQuery('option').hide();
//Potential solution number 3... (doesn't work in safari and still has the issue of working out which selects to hide)
//jQuery('select').hide();
//Potential solution number 4... (doesn't hide drop down options at all and would also need to know which selects to disable)
//jQuery('select').attr('disabled','disabled');
//Potential solution number 5... (doesn't work at all)
//jQuery(".hover-here").click();
//Potential solution number 6... (doesn't work in safari or chrome)
//jQuery('.other-input').focus();
//Potential solution number 7... (doesn't work in safari)
//innerHtml = jQuery('.problem-select').html();
//value = jQuery('.problem-select').children("input").val();
//jQuery('.problem-select').html(innerHtml);
//jQuery('.problem-select').children("select").val(value);
jQuery('.overlapping-div').show();
}
function hideDiv() {
//Potential solution number 2 cont...
//jQuery('option').show();
//Potential solution number 3 cont...
//jQuery('select').show();
//Potential solution number 4 cont...
//jQuery('select').attr('disabled',null);
jQuery('.overlapping-div').hide();
}
選択ボックスをクリックして開き、選択ボックスからオプションを選択したり、ページの他の場所をクリックしたりせずに右側の div にカーソルを合わせると、表示される赤い div の上に選択オプションが表示されます。 .
私が試したことのいくつかはフィドルにあり、関連するセクションのコメントを外して、何が起こるかを確認する必要があります。それらのほとんどは Firefox で動作し、サファリでは動作しません。
実際のアプリケーションで私が直面している追加の問題は、選択ボックスが赤い div の下にある場合とない場合があるため、選択ボックスのオプションが赤い div を覆い隠すか、引き続き許可するかを決定できるようにする必要があることです。通常の使用 (オプションの選択)。(アプリケーションでは、ページで他のアクションを実行している間、赤い div を表示したままにすることができます)。
赤い div で覆われていない場合、選択ボックスの機能に影響を与えずに、chrome、safari、ie7-9、および firefox の赤い div の上に表示されるオプション リストを停止するにはどうすればよいですか?
私の経験では、さまざまなイベントで定期的にトリガーされる機能を変更するアプリケーションではうまく機能しないため、他のhtml要素を使用して選択ボックスを再作成するプラグインの使用を避けようとしています。