您可以使用jquery并使用"name"属性进行选择.此外,您可以使用jquery"parent()"函数来获取您有兴趣显示/隐藏的输入的容器.
例如,在您的架构中执行以下操作:
# This is the "<select>"
choices = (('yes','Yes'),
           ('no', 'No'))
bar = colander.SchemaNode(colander.String(),
                          widget=deform.widget.SelectWidget(values=choices))
# This is the input that should appear only when the "yes" value is selected
foo = colander.SchemaNode(colander.String())
然后,在您的模板中添加以下内容:
<script>
$( document ).ready(function() {
// ensure that the "foo" input starts hidden
var target = $("input[name=foo]").parent().parent();
target.hide();
$("select[name=bar]").on('change', function(){
    var valueSelected = this.value;
    if (valueSelected == "yes") {
      target.show();
    } else {
      target.hide();
    }
});
});
</script>