Javascript HTML显示格式有问题吗?
在我的应用程序中,我需要选择图像。所以我使用类型为“file”的输入标记。UI如下图所示Javascript HTML显示格式有问题吗?,javascript,html,jquery-mobile,Javascript,Html,Jquery Mobile,在我的应用程序中,我需要选择图像。所以我使用类型为“file”的输入标记。UI如下图所示 <input type="file" id="fileUploader"> 如何将上述输入标记写入 试试这个: $(function(){ $('#anchorlink').click(function(){ $(this).replaceWith('<input type="file" id="fileUploader" />'); $('#f
<input type="file" id="fileUploader">
如何将上述输入标记写入
试试这个:
$(function(){
$('#anchorlink').click(function(){
$(this).replaceWith('<input type="file" id="fileUploader" />');
$('#fileUploader').click();
})
});
<a href="#" id="anchorlink" >click<img src="stylish.png"/></a>
$(函数(){
$('#anchorlink')。单击(函数(){
$(此)。替换为(“”);
$(“#文件上载程序”)。单击();
})
});
比
A
更好的选择是使用标签
和用于,并隐藏输入
演示:
标记:
使用jquery mobile更改默认文件选择器,请尝试如下操作
HTML类似于:
<span class="ui-btn ui-icon-plus ui-btn-icon-left ui-corner-all fileinput-button">
<span>Pick File </span>
<input type="file" name="files" multiple data-role="none"/>
</span>
我想这是你需要的
<img onclick="javascript:document.getElementById('myFile').click();" src="http://www.clker.com/cliparts/O/r/K/T/t/n/camera-icon-hi.png" style="width:50px;height:auto" />
<input type="file" id="myFile" style="display:none" />
我只是隐藏我的输入文件,让图像的onclick
属性显示对话框
请参考我下面的样本
我不需要显示/隐藏方法。我需要一次单击图像,然后选择文件,无需再次单击浏览按钮Use$(“#fileUploader”)。单击();选择此自动文件后。请检查此选项
#fileUploader {
display: none;
}
label[for=fileUploader] {
display: inline-block;
width: 128px; height: 128px;
cursor: pointer;
background: url('your-camera-image-here') no-repeat left center;
}
<span class="ui-btn ui-icon-plus ui-btn-icon-left ui-corner-all fileinput-button">
<span>Pick File </span>
<input type="file" name="files" multiple data-role="none"/>
</span>
.fileinput-button {
position: relative;
overflow: hidden;
float: left;
margin-right: 4px;
}
.fileinput-button input {
position: absolute;
top: 0;
right: 0;
margin: 0;
opacity: 0;
filter: alpha(opacity=0);
transform: translate(-300px, 0) scale(4);
font-size: 23px;
direction: ltr;
cursor: pointer;
}
<img onclick="javascript:document.getElementById('myFile').click();" src="http://www.clker.com/cliparts/O/r/K/T/t/n/camera-icon-hi.png" style="width:50px;height:auto" />
<input type="file" id="myFile" style="display:none" />