【问题标题】:JQuery fill the form but failed to be recognizedjQuery填写表格但未能被识别
【发布时间】:2014-12-10 11:44:03
【问题描述】:

我使用 Flask 作为后端。我用 WTForm 写了一个简单的表单,比如说,

field = StringField('input:', validators=[Required()])

我写了一个 JQuery 来自动填充它

$('#theidofthefield').val('fillingin');

然后我单击表单中的提交按钮,但它显示该字段为空。我检查 request.form.field.data 也是空的。 希望得到解决方案。

【问题讨论】:

    标签: javascript jquery flask flask-wtforms


    【解决方案1】:

    我不知道WTForm,但您可以检查您的字段元素是否具有 name 属性,该属性是发送回后端代码所必需的。

    您的字段必须是这样的:

    <input type="text" name="thenameofthefield" id="theidofthefield" />
    //-----------------^^^^^^^^^^^^^^^^^^^^^^^---name attribute is required.
    

    【讨论】:

      【解决方案2】:

      另一种填充值的方法是:

      $('#theidofthefield').attr('value','filling');
      

      让我们看看它是否有效..

      如果变量字段是指向对象的指针,那么.. $(field).val('dfsdf') 或 $(field).attr('value','filling') 可能有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-28
        • 2022-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多