HTML显示格式问题?

时间:2014-06-30 08:10:49

标签: javascript html html5 jquery-mobile

在我的应用程序中,我需要选择图像。所以我使用" file"类型的输入标签。用户界面如下图所示

<input type="file" id="fileUploader">

enter image description here

如何将上述输入标记写为<a>标记,以便在点击相机图像时我需要选择文件,

<a href="#" onClick='#'><img src="img/camera.jpg"/></a>

4 个答案:

答案 0 :(得分:1)

尝试使用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>

css就像:

.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;
    }

FIDDLE DEMO

答案 1 :(得分:0)

试试这个:

    $(function(){ 
     $('#anchorlink').click(function(){
    $(this).replaceWith('<input type="file" id="fileUploader" />'); 
$('#fileUploader').click(); 
    })
    });




<a href="#" id="anchorlink" >click<img src="stylish.png"/></a> 

http://jsfiddle.net/dQHh5/3/

答案 2 :(得分:0)

a更好的选择是将labelfor一起使用,并隐藏input

演示:http://jsfiddle.net/abhitalks/GpsAJ/

标记

<label for="fileUploader" />
<input type="file" id="fileUploader" />

CSS

#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;
}

答案 3 :(得分:0)

我认为这是你需要的

<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属性显示对话框..

请参阅下面的示例。

http://jsfiddle.net/fbB46/