douzhi9395 2017-05-20 08:56
浏览 34
已采纳

如何一次验证文本框或浏览按钮?

I have question about how to validate input type=text or textbox OR input type="file" upload a file at a time using javascript or jquery?

1) If textbox is selected than no need to upload file. 2) If upload file is selected than no need to textbox. 3) Both

  • 写回答

2条回答 默认 最新

  • doutun1362 2017-05-20 09:03
    关注

    simple with required attribute

    <form>
    <input type="text" required="true">
    <input type="file"  required="true">
    <button type="submit">validate</button>
    </form>

    Or with Javascript validation

    Updated

    $('button').click(function(){
     var a =$(".validate").map(function(){
      return $(this).val().trim() ? true : false
    }).get()
    if(a.includes(true)){
    console.log('pass')
    }
    else{
    console.log('select any one')
    }
    })
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <input type="text" class="validate">
    <input type="file" class="validate">
    <button>validate</button>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改