0

以下で構成されるwtformsカスタムフォームを作成しています

  • 複数のブールチェックボタン/ラジオボタン

  • 隠しテキスト入力。

  • ユーザーが「その他」ボタンをクリックすると、テキスト入力が有効になり、ユーザーは手動で何かを書くことができます

  • ユーザーが「その他」ボタンをクリックしないと、テキスト入力が無効になります。

これを描画するウィジェット関数は次のとおりです(複数のチェックボックスの場合):

def select_multi_other_checkbox(field, ul_class='', **kwargs):
    """check wtforms.widgets.core to see what is going on"""
    kwargs.setdefault('type', 'checkbox')
    field_id = kwargs.pop('id', field.id)
    html = [u'<ul %s>' % html_params(id=field_id, class_=ul_class)]
    for value, label, checked in field.iter_choices():
        choice_id = u'%s-%s' % (field_id, value)
        options = dict(kwargs, name=field.name, value=value, id=choice_id)
        if checked:
            options['checked'] = 'checked'
        html.append(u'<li><input %s /> ' % html_params(**options))
        html.append(u'<label %s>%s</label></li>' % (html_params(**options), cgi.escape(text_type(label))))

    else:
        choice_id = u'%s-%s' %(field_id, u'other')
        options = dict(kwargs, name=field.name, value='', id = choice_id)
        options['type'] = 'text'
        html.append(u'<input %s > ' % (html_params(**options)))

    html.append(u'</ul>')
    cPickle.dump(html, open("htmltest.p", "wb"))
    return u''.join(html)

その部分html.append(u'<input %s > ' % (html_params(**options)))は、テキスト入力が追加された場所です。(タグの属性をoptions['type'] = 'text'意味することに注意してください)質問は、後でjqueryを介して明らかにできるように、隠しテキスト入力(ではない)を作成するにはどうすればよいですか?type="text"<input>type="hidden"

4

1 に答える 1

1

それを隠すスタイルを追加します。

<input type="text" style="display:none" id="myhiddentextfield" />

次に、jQuery を使用して表示します。

$('#myhiddentextfield').show();
于 2013-02-04T22:19:36.640 に答える