在我的 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?
}
});
我可以用拔头发的方式来做(这对我来说非常痛苦,因为我的头发几乎和 Absalom 一样多),并设置每个单独的元素,如下所示:
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
}
当然有更优雅/更好的方法!
是将所有有条件不可见的元素分配给特定的类,然后使分配给该类的每个元素不可见,还是什么?
另外,我希望这片现在看不见的地带以前使用的区域“消失”或“卷起”,而不是坐在那里,茫然地凝视,张开裂口,或者戈壁沙漠般毫无特色的广阔区域。