如何根据枚举值隐藏和显示命名div?

时间:2016-03-01 03:29:34

标签: javascript jquery jsp enums

我试图隐藏并显示基于枚举的div。我知道这应该很简单,但我的JavaScript(和jQuery)非常生疏。

我的选择表格是:

weekInterval

Where我还有一堆div声明为:

monthInterval

alert(recurrency); if (recurrency.value == 'DAILY') { $('weekInterval').hide(); document.getElementById('weekInterval').style.display = 'block'; document.getElementById('monthInterval').style.display = 'block'; } if (recurrency.value == 'WEEKLY') { document.getElementById('dayInterval').style.display = 'block'; document.getElementById('monthInterval').style.display = 'block'; } if (recurrency.value == 'MONTHLY') { document.getElementById('dayInterval').style.display = 'block'; document.getElementById('weekInterval').style.display = 'block'; } }); }); Object HTMLCollection相同。

我的JavaScript代码是:

$().ready(function () {
            $('#recurrency').on('change', function () {

def multiplication_table(n): import numpy as np base = list(range(1, n+1)) array_shell = np.zeros(shape=(n,n), dtype=int) array_shell[0] = base for row in range(1,len(base)): array_shell[row][0] = base[row] for row in range(1, len(base)): for idx in range(1, len(base)): array_shell[row][idx] = base[idx]*array_shell[row][0] return (array_shell) my_int = 8 print(multiplication_table(my_int))

JavaScript代码的警报部分始终返回int values = 4375; String mValue = String.valuOf(values); Char mChar = mValue.chatAt(int index); int selectedValue = Character.getNumericValue(mChar); 。我确信这很简单,但我看不出这里的出路。

有人可以拉我一只手吗?提前谢谢!

1 个答案:

答案 0 :(得分:0)

您需要拥有select元素的更改事件处理程序。然后在change事件处理程序中,您可以获取select的值,然后使用.toggle()

设置目标元素的显示

在您的情况下,recurrency引用div元素(因为这是div的ID),这就是您收到类似警告消息的原因。



$(function() {
  $('#recurrency select').on('change', function() {
    var value = this.value;
    $('#dayInterval').toggle(value == 'DAILY');
    $('#weekInterval').toggle(value == 'WEEKLY');
    $('#monthInterval').toggle(value == 'MONTHLY');
  }).change();
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="recurrency">
  <select path="recurrency">
    <option value="-" label="--Please Select" />
    <option value="DAILY">DAILY</option>
    <option value="WEEKLY">WEEKLY</option>
    <option value="MONTHLY">MONTHLY</option>
  </select>
</div>

<div id="dayInterval">DAILY</div>
<div id="weekInterval">WEEKLY</div>
<div id="monthInterval">MONTHLY</div>
&#13;
&#13;
&#13;

相关问题