2016-04-30 35 views
0

我有以下代码:INPUT TYPE =“文件”的onclick工作,但文件选择犯规显示

<a id="newPhoto" class="new-image no-expand"> 
    <input onclick="alert('cocos')" type="file" style="display: block; position: absolute; z-index: 1500"/> 
    <button class="btn btn-primary btn-upload clickable no-expand" 
      style="font-family: Montserrat, 'Helvetica Neue', Helvetica, Arial, sans-serif;"> 
    <i class="fa fa-upload"></i> Upload 
    </button> 
    <br><br> 
    <div title="Remove" class="btn-remove"> 
     <span class="glyphicon glyphicon-remove" style="color: white"></span> 
    </div> 
</a> 

现在点击input时的click按钮上的视觉效果被触发,藏汉作为onclick事件处理程序,但由于某种原因弹出对话框使我选择一个文件没有。我也尝试删除任何CSS,并确保该确切的项目被点击,并且它不被其他div或类似的东西覆盖。任何想法?

回答

0

该问题是由于我在a内嵌套input而引起的。这不是有效的HTML。但是,如果我不使用Angular,它可能会有效,如果它没有src属性,则任何点击任何<a>都不会执行任何操作。

var htmlAnchorDirective = valueFn({ 
restrict: 'E', 
compile: function(element, attr) { 
    if (!attr.href && !attr.xlinkHref) { 
    return function(scope, element) { 
     // If the linked element is not an anchor tag anymore, do nothing 
     if (element[0].nodeName.toLowerCase() !== 'a') return; 

     // SVGAElement does not use the href attribute, but rather the 'xlinkHref' attribute. 
     var href = toString.call(element.prop('href')) === '[object SVGAnimatedString]' ? 
       'xlink:href' : 'href'; 
     element.on('click', function(event) { 
     // if we have no href url, then don't navigate anywhere. 
     if (!element.attr(href)) { 
      event.preventDefault(); 
     } 
     }); 
    }; 
    } 
} 
}); 

将容器更改为一个div解决了问题。

0

在您的代码中,单击警告框中的确定按钮后,会出现文件对话框。 Click Here

Please see my code in the above Link.