位置绝对和溢出隐藏(Position absolute and overflow hidden)
我们有两个DIV,一个埋在另一个。 如果外部DIV不是绝对的,则绝对位置的内部DIV不会遵守外部DIV( 示例 )隐藏的溢出。
有没有机会使内部DIV服从外部DIV隐藏的溢出,而不设置外部DIV定位绝对(因为这将填补我们的完整布局)? 我们内部DIV的位置也不是一个选择,因为我们需要“扩展”TD表( 例如 )。
还有其他选择吗?
We have two DIVs, one embedded in the other. If the outer DIV is not positioned absolute then the inner DIV, which is positioned absolute, does not obey the overflow hidden of the outer DIV (example).
Is there any chance to make the inner DIV obey the overflow hidden of the outer DIV without setting the outer DIV to position absolute (cause that will muck up our complete layout)? Also position relative for our inner DIV isn't an option as we need to "grow out" of a table TD (exmple).
Are there any other options?
原文:https://stackoverflow.com/questions/4605715
最满意答案
您可以向它们添加类,而不是显示/隐藏每个元素:
<select id="selFather"> <option id="fnoble" value="fnoble" class="f">a Noble (f)</option> <option id="mnoble" value="mnoble" class="m">a Noble (m)</option> <option value="merchant">a Merchant</option> <option value="vetwarrior">a Veteran Warrior</option> <option value="thief">a Thief</option> <option id="fnomad" value="fnomad" class="f">a Nomad (f)</option> <option id="mnomad" value="mnomad" class="m">a Nomad (m)</option> </select>
接着
$('.f').hide(); $('.m').show();
您还可以创建一个CSS样式表:
.f{display:none} .m{display:block;}
你的代码有问题:如果你有......
<select id="selGender"> <option value="1" >Male</option> <option value="2">Female</option> </select>
...默认选中的值为“Male”,因此如果选择它,则不会触发onchange事件。 您可以使用
<select id="selGender"> <option selected="selected" disabled="disabled">Select gender:</option> <option value="1" >Male</option> <option value="2">Female</option> </select>
而且,你有
if (sGender = 1)
你应该用
if (sGender == 1)
因为你正在比较,而不是设定值。
关于您的另一个问题(在表格中导航),您可以创建一个JavaScript函数来执行该操作。 但是我不太清楚你想要什么,“左边两个细胞中的第三个细胞”。
编辑:
如果我理解得很好你有一张像这样的桌子
<table id="table"> <tbody> <tr> <td>Skill 1</td> <td>Skill 2</td> <td>Skill 3</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> </tr> </tbody> </table>
你想要的
table(1,1)=Skill 1 cell table(1,2)=Value 1 cell table(2,1)=Skill 2 cell table(2,2)=Value 2 cell ...
然后,
function table(col,row){ return document.getElementById('table').tBodies[0].getElementsByTagName('tr')[row-1].getElementsByTagName('td')[col-1]; }
在这里看到: http : //jsfiddle.net/UGHHd/
See http://jsfiddle.net/KvNVN/
Instead of showing/hiding each element, you can add classes to them:
<select id="selFather"> <option id="fnoble" value="fnoble" class="f">a Noble (f)</option> <option id="mnoble" value="mnoble" class="m">a Noble (m)</option> <option value="merchant">a Merchant</option> <option value="vetwarrior">a Veteran Warrior</option> <option value="thief">a Thief</option> <option id="fnomad" value="fnomad" class="f">a Nomad (f)</option> <option id="mnomad" value="mnomad" class="m">a Nomad (m)</option> </select>
And then
$('.f').hide(); $('.m').show();
You could also create a CSS stylesheet with:
.f{display:none} .m{display:block;}
Your code has a problem: if you have ...
<select id="selGender"> <option value="1" >Male</option> <option value="2">Female</option> </select>
... the default selected value is "Male", so if you select it it doesn't trigger onchange event. You can use
<select id="selGender"> <option selected="selected" disabled="disabled">Select gender:</option> <option value="1" >Male</option> <option value="2">Female</option> </select>
Moreover, you have
if (sGender = 1)
You should use
if (sGender == 1)
because you are comparing, not setting values.
About your other question (navigate through a table), you can create a JavaScript function which does that. But I don't understand very well what you want with "the third cell from the left two cells down".
Edit:
If I understand well you have a table like
<table id="table"> <tbody> <tr> <td>Skill 1</td> <td>Skill 2</td> <td>Skill 3</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> </tr> </tbody> </table>
And you want
table(1,1)=Skill 1 cell table(1,2)=Value 1 cell table(2,1)=Skill 2 cell table(2,2)=Value 2 cell ...
Then,
function table(col,row){ return document.getElementById('table').tBodies[0].getElementsByTagName('tr')[row-1].getElementsByTagName('td')[col-1]; }
See it here: http://jsfiddle.net/UGHHd/
相关问答
更多-
当选择其他选项时,如何在选择中显示/隐藏选项(How can I show/hide options in a select when another option is selected)[2022-05-06]
见http://jsfiddle.net/KvNVN/ 您可以向它们添加类,而不是显示/隐藏每个元素: -
首先,在选项中你有值'GB'而在if语句中你正在检查if($(this).val() == 'UK') 。 另外,我建议使用以下方法清除添加的动态select标记: $(this).next().remove(); 最后一点是括号有问题。 正确的解决方案: $('#calc_shipping_country').change(function(){ $(this).next().remove(); if($(this).val() == 'GB'){ $('#calc_shipping_co ...
-
如何在选择框中隐藏较长的文本,并在将其显示为选项时将其包装(How to hide longer text in select box and wrap it when showing it as a option)[2023-06-03]
试试这个功能: // shorten_options( selectElement[, max_length] ); function shorten_options(elem, max) { var options = elem.options, op, i; max = max ? max - 3 : 7; for (i = 0; i < options.length; i += 1) { op = options[i]; if (op.textC ... -
当选择多个选项时,在Select2事件中获取选定的选项(Get selected option in Select2 event, when multiple options can be selected)[2023-08-10]
我已经使用以下来获取在Select2中选择的当前版本(它适用于版本4及以上版本): // single value var test = $('#test'); test.on("select2:select", function(event) { var value = $(event.currentTarget).find("option:selected").val(); console.log(value); }); 更新:多选定值(有和没有上次选择) // multi values, w ... -
如果您想要跨浏览器, 隐藏选项不正确。 您应该动态插入/删除/禁用选项。 $(function() { $("#SelectFeatures").on("click", "option", function() { var _optgroup_index = $(this).parent().index(); var _optgroup_label = $(this).parent().attr("label"); var $optgroup = $('#Selected ...
-
在选择中显示/隐藏选项(Show/Hide options in a select)[2020-02-08]
IE中不存在select中隐藏options的概念。 您必须手动删除并重新添加条目,这可能会带来一些不便。 另一种解决方案是禁用元素 $("input:radio").on('change click',function(){ $("select#typeDeProduit > option").hide().prop('disabled', false); cacherTousTypesDeProduit(); rafraichirListeTypeDeP ... -
隐藏/显示基于jQuery中另一个选择器选项的选择选项(Hide / Show select options based on another selector's option in jQuery)[2024-05-14]
the modified plugin is: jQuery.fn.filterOn = function(selection, values) { return this.each(function() { var select = this; var options = []; $(select).find('option').each(function() { option ... -
我建议你依靠Angular来做这件事而忘记直接使用jQuery ,因为它没有必要。 您可以做的是拥有所有选项的主列表,并为选择维护两个单独的列表。 选择更改后,您将重建列表。 这里的示例不是基于您的plunker中的代码,而是基于PoC。 您应该注意的是,一个选择列表中的选定选项不能成为另一个选项中的选项。 angular.module('app', []) .controller('controller', function() { var self = this; self.m ...
-
显示/隐藏按类选择选项(Show/hide Select options by class)[2022-11-30]
我不会使用hide / show。 我只是操纵元素 $('select').focus(function() { var option = $(this).find("option[value*=Default]"); option.attr('value', option.attr('value').match(/[0-9]+/)); }); http://jsfiddle.net/JHAPp/2/ 使用focus来检测用户是否与选择进行了交互。 当发生这种情况时,从值中删除_Defau ... -
当选项基于另一个选择时,保持选定选项显示(keep selected option displayed when options based on another select)[2024-02-27]
我可以在提交后捕获第二个