如果选择了另一个,则禁用输入字段?

时间:2016-03-09 12:04:49

标签: javascript jquery html ajax

如果用户点击以下字段并选择文件

,如何完成此操作
<input type="file" name="file" id="file"/>

然后

<input type="text" name="ytube" id="ytube" value="" />

被禁用,如果你点击了管,那么图像选项会被禁用吗?

提前感谢:)

4 个答案:

答案 0 :(得分:0)

使用jquery

  $(function() {
     $("input:file").change(function (){
       $("#ytube").prop('disabled', true);
     });
     $("#ytube").change(function (){
       if($("#ytube").val().trim() != ""){
          $("#file").prop('disabled', true);
       }else{
          $("#file").prop('disabled', false);
       }

     });
  });

https://jsfiddle.net/m3hu2ruc/4/

答案 1 :(得分:0)

你可以尝试这个

$(document).ready(function(){
    $('input#file"]').change(function(){
        $('#ytube').attr('disabled','disabled');    
    });
});

答案 2 :(得分:0)

如果您只想在选择文件时禁用文本框,请使用此代码

<强> CODE

$('input:file').change(function(){
   if($(this).val()!=''){
     $('input:text').prop('disabled','disabled');
   }
})

要在文本框上禁用输入文件,请单击

<强> CODE

$('input:text').on('click', function(){
  $('input:file').prop('disabled','disabled');
})

答案 3 :(得分:0)

试试这样。

<?php
 $result = mysql_query("SELECT text FROM mutable WHERE (id_obj = 1)");
 while($row = mysql_fetch_array($result)){  
 echo "<p>" . html_entity_decode($row['text']) . "</p>";  
}

如果要从文本输入框中删除文本,将再次启用文件输入。但我建议按一下按钮重置。

相关问题