【发布时间】:2015-06-17 18:15:04
【问题描述】:
在我的 Sharepoint 项目/Web 部件/网页中,我在 *.ascx.cs 文件中使用 C# 动态创建页面元素/控件。
在 *.ascx 文件中,我使用 jQuery 来响应页面上发生的事件(选择、复选框状态的更改等)。
我需要有条件地隐藏页面上的控件/元素组。具体来说,如果用户选中某个复选框,我可以“删除”整个页面,在这种情况下,不适用于她。
我该怎么做?我有这个起点:
/* If the select "Yes" (they are seeking payment for themselves, as opposed to someone else), omit (invisibilize) sections 2 and 3 on the form */
$(document).on("change", '[id$=ckbxPaymentForSelf]', function () {
var ckd = this.checked;
if (ckd) {
// what now?
}
});
我可以用拔头发的方式(这对我来说很痛苦,因为我的头发几乎和押沙龙一样多),然后设置每个单独的元素,如下所示:
if (ckd) {
var $this = $('[id$=txtbxthis]');
var $that = $('[id$=txtbxthat]');
var $theother = $('[id$=txtbxtheother]');
. . . // store a reference to all the other to-be-affected elements in vars
$this.visible = false; // <= this is pseudoscript; I don't know what the jQuery to invisiblize an element is
$that.visible = false; // " "
$theother.visible = false; // " "
. . . // invisiblize all the other to-be-affected elements
}
肯定有更优雅/更好的方法!
是将所有有条件的不可见元素分配给特定类,然后使分配该类的每个元素不可见,还是什么?
另外,我希望这片现在看不见的地带以前使用的区域“走开”或“卷起”,而不是呆在那儿,面无表情,打着哈欠的鸿沟,或者像戈壁沙漠一样毫无特色的广阔。
【问题讨论】:
-
来重新检查我的代码,我想我可以简化我必须的“if (this.checked)”
标签: javascript c# jquery sharepoint-2010 invisible