douji3426
douji3426
2014-08-29 11:30

Jasny BootStrap,输入类型的设置值=“file”

已采纳

im using Jasny Bootstrap library

http://jasny.github.io/bootstrap/

im using the file input field.

                <div class="form-group">
                    <label class="control-label col-lg-2">Site Logo</label>
                    <div class="col-lg-10">
                        <div class="fileinput fileinput-new input-group" data-provides="fileinput" id="fileInputSiteLogo">
                            <div class="form-control" data-trigger="fileinput"><i class="glyphicon glyphicon-file fileinput-exists"></i> <span class="fileinput-filename"></span></div>
                            <span class="input-group-addon btn btn-default btn-file"><span class="fileinput-new">Select file</span><span class="fileinput-exists">Change</span><input type="file" name="siteLogo"></span>
                            <a href="#" class="input-group-addon btn btn-default fileinput-exists" data-dismiss="fileinput">Remove</a>
                        </div>
                    </div>
                </div><!-- /.form-group -->

Problem is i want to set the value in to that.

for normal TextBox in jQuery i know it is

$('#inputselector').val($phpVariable);

and in HTML it is

value = "<?php echo $phpVariable ?>"

i have data coming from database and i want to set the existing value to this file input field.

Please tell for both HTML and jQuery if possible.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douli1854 douli1854 7年前

    The file name is displayed in .fileinput-filename.

    <span class="fileinput-filename"><?php echo $phpVariable ?></span>
    

    or using JavaScript

    var filename = "<?php echo $phpVariable ?>";
    $('#myFileUpload .fileinput-filename').text(filename);
    

    This example doesn't do proper escaping.

    点赞 评论 复制链接分享