【问题标题】:How to write pre filled input in bootbox如何在引导箱中编写预填充输入
【发布时间】:2021-11-11 10:38:30
【问题描述】:

我希望引导箱在单击更新按钮时将 var name 填充到引导箱输入中,但它没有这样做。我还在下面的代码中突出显示了相同的内容

$(document).on("click", ".update", function () {
      var button = $(event.relatedTarget); /*Button that triggered the modal*/
      var name = button.data('name');
      modal.find('.bootbox-input-text').val(name); 
      $('.bootbox-form').find('input').val(name); /* Not Working */
      bootbox.prompt({
        title: 'Enter Description',
        placeholder: 'my placeholder',
        
        buttons: {
          confirm: {
            label: 'Submit'
          }
        },
        callback: function (value) {
          value && alert('You have entered: ' + value);
        }
      });
    });

【问题讨论】:

    标签: javascript bootbox


    【解决方案1】:

    documentation 中所述,您可以使用value 选项为提示提供初始值:

    $(document).on('click', '.update', function (e) {
        let button = $(this); /*Button that triggered the modal*/
        let name = button.data('name');
        
        bootbox.prompt({
            title: 'Enter Description',
            placeholder: 'my placeholder',
    
            value: name, /* this is the option you would use */
    
            buttons: {
              confirm: {
                label: 'Submit'
              }
            },
            callback: function (value) {
              value && alert('You have entered: ' + value);
            }
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2014-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多