文件路径

用选择文件<input type="file">,原始样式不怎么好看,想要好看一点,就要自己写样式来代替原始的样式
//原始的样式
在这里插入图片描述
//自己写的样式
在这里插入图片描述

<label class=“mt-2”>附件途径:</label>
<div class=“custom-file”>
//选择文件原始样式
<input type=“file” id=“choicefile”>
//输入框
<input type=“text” class=“d-inline-block” id=“filename”>
//绑定选择文件的点击按钮
// “for” 属性可把 label 绑定到id为choicefile里
// for: “id”
<label class=“form-control form-control-sm text-white text-center ml-2 mt-2” style=“width:80px;height:30px;background-color:#5cb85c;cursor:
pointer;” for=“choicefile”>浏览</label>
</div>

在这里插入图片描述
在这里插入图片描述
隐藏选择文件的原始样式 hidden
onchange在元素值改变时触发,点击浏览选择文件打开,会获取到选择文件的原始样式的value值,把值给到id为’filename’的input的value

//代码
<label class="mt-2">附件途径:</label>
<div class="custom-file">
	<input type="file" id="choicefile" onchange="document.getElementById('filename').value = this.value;" hidden>

	<input type="text" class="form-control form-control-sm d-inline-block" style="margin-left:20px;" id="filename">

	<label class="form-control form-control-sm text-white text-center ml-2 mt-2" style="width:80px;height:30px;background-color:#5cb85c;cursor: pointer;" for="choicefile">浏览</label>
</div>

没有选择到文件的
在这里插入图片描述

选择到文件的
点击浏览,会跳出选择文件的框,选择好了文件,打开,input 里就会显示出你选择文件的路径
如图
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值