根据文本框值隐藏checkbox / div

时间:2018-03-13 06:20:29

标签: javascript asp.net-mvc

我有一个下拉列表,当我选择一个项目时,其categoryId被分配给文本框。然后我有2个复选框' IsAnonymous'和' ShowReport'。我想实现的是,文本框中的值为1,然后两个复选框都是可见的,当值为2时,则显示#Re;' ShowReport'必须隐藏复选框。

--data definition
declare @contactTable table (contactId int, linkContactId int)
insert into @contactTable values
(1,21),
(2,null),
(3,450),
(4,1),
(5,900),
(6,5),
(7,3),
(8,1)
--recursive cte
;with cte as (
    (select 1 n, contactId from @contactTable
    where linkContactId = 1
    union
    select 1, linkContactId from @contactTable
    where contactId = 1)

    union all
    --this part might seem confusing, I tried writing recursive part similairly as anchor part,
    --but it needed to joins, which isn't allowed in recursive part of cte, so I worked around it
    select n + 1,
           case when cte.n + 1 = t.contactId then t.linkContactId else t.contactId end
    from cte join @contactTable [t] on
    (cte.n + 1 = t.contactId or cte.n + 1 = t.linkContactId)
)
--grouping results by contactId concatenating all linkContacts
select n [contactId],
       (select distinct cast(contactId as varchar(5)) + ',' from cte where n = c.n for xml path(''), type).value('(.)[1]', 'varchar(100)') [linkContactId]
from cte [c]
group by n

查看

javascript
var ReportDiv = $('#ReportDiv');
$('#cmbCategories').on('change', function () {
    if ($(this).val() == '1') {
        ReportDiv.hide();
    }
    else {

        ReportDiv.show();
    }
});

Added a picture to give idea of my page

0 个答案:

没有答案