ThinkAdmin/application/demo/view/inter.file.html
2017-07-11 10:34:09 +08:00

121 lines
3.4 KiB
PHP

{extend name='extra@admin/content'}
{block name="content"}
<style>
.uploadbutton {
line-height: 50px;
display: inline-block;
position: absolute;
margin-left: 10px;
top: 20px;
}
</style>
<div class="code">
<blockquote class="site-text layui-elem-quote">
单图片上传
</blockquote>
<div style="position:relative">
<div class="uploadimage">
<input type="hidden" name="file_1"/>
</div>
<a data-file="one"
data-field="file_1"
data-type="png,jpg"
data-uptype="local"
href="javascript:void(0)"
class="uploadbutton">上传图片</a>
</div>
<script>
require(['jquery'], function () {
$('[name="file_1"]').on('change', function () {
$(this).parent().css('backgroundImage', 'url(' + this.value + ')');
$(this).parent().attr('data-tips-image', this.value);
});
});
</script>
<pre class="layui-code" lay-title="HTML代码">
<div style="position:relative">
<div class="uploadimage">
<input type="hidden" name="file_1"/>
</div>
<a data-file="one"
data-field="file_1"
data-type="png,jpg"
data-uptype="local"
href="javascript:void(0)">上传图片</a>
</div>
</pre>
<pre class="layui-code" lay-title="javascript代码">
// 监听 input 的 onchange 事件
// 当有图片上传时,会触发 change 事件
require(['jquery'], function () {
$('[name="file_1"]').on('change', function () {
$(this).parent().css('backgroundImage', 'url(' + this.value + ')');
$(this).parent().attr('data-tips-image', this.value);
});
});
</pre>
</div>
<div class="code">
<blockquote class="site-text layui-elem-quote">
单文件上传
</blockquote>
<div style="position:relative">
<div class="input-group">
<input type="text" class="form-control" name="file_2" placeholder="请选择文件...">
<a class="input-group-addon"
data-file="one"
data-type="zip"
data-uptype="local"
data-field="file_2">
<i class="fa fa-file"></i>
</a>
</div>
</div>
<script>
require(['jquery'], function () {
$('[name="file_1"]').on('change', function () {
$(this).parent().css('backgroundImage', 'url(' + this.value + ')');
$(this).parent().attr('data-tips-image', this.value);
});
});
</script>
<pre class="layui-code" lay-title="HTML代码">
<div style="position:relative">
<div class="uploadimage">
<input type="hidden" name="file_1"/>
</div>
<a data-file="one"
data-field="file_1"
data-type="png,jpg"
data-uptype="local"
href="javascript:void(0)">上传图片</a>
</div>
</pre>
<pre class="layui-code" lay-title="javascript代码">
// 监听 input 的 onchange 事件
// 当有图片上传时,会触发 change 事件
require(['jquery'], function () {
$('[name="file_1"]').on('change', function () {
$(this).parent().css('backgroundImage', 'url(' + this.value + ')');
$(this).parent().attr('data-tips-image', this.value);
});
});
</pre>
</div>
<script>
layui.use('code', function () {
layui.code({
encode: true
});
});
</script>
{/block}