Удалите параметр Chrome «Файл не выбран» из ввода файла с помощью JavaScript.

Опубликовано: 27 Июня, 2021

Задача состоит в том, чтобы удалить значение «файл не выбран» из пустого элемента ввода в chrome. Мы собираемся решить эту задачу с помощью JavaScript.

Подход 1:

  • Удалите значение всплывающей подсказки («Файл не выбран»).
  • Используйте метод .attr (), чтобы установить значение атрибута title пустым.

Пример 1. В этом примере удаляется значение всплывающей подсказки.




<!DOCTYPE HTML>
< html >
< head >
< title >
Remove the “No file chosen” from a file input in Chrome?
</ title >
< script src =
</ script >
</ head >
< body style = "text-align:center;"
id = "body" >
< h1 style = "color:green;" >
GeeksForGeeks
</ h1 >
< p id = "GFG_UP"
style="font-size: 15px;
font-weight: bold;">
</ p >
< div >
< type input = 'file' />
</ div >
< br >
< button onclick = "gfg_Run()" >
Remove tooltip
</ button >
< p id = "GFG_DOWN"
style="color:green;
font-size: 20px;
font-weight: bold;">
</ p >
< script >
var el_up = document.getElementById("GFG_UP");
var el_down = document.getElementById("GFG_DOWN");
el_up.innerHTML =
"Click on the button to remove the tooltip value '" +
"No file is chosen.'";
function gfg_Run() {
$('input').attr('title', '');
el_down.innerHTML =
"Tooltip value has been removed.";
}
</ script >
</ body >
</ html >

Выход:

  • Перед нажатием на кнопку:
  • После нажатия на кнопку:

Подход 2:

  • Удалите значение («Файл не выбран»).
  • Используйте метод .addClass (), чтобы добавить класс, который удаляет значение «Файл не выбран».

Пример 2: В этом примере удаляется значение «Файл не выбран» из элемента ввода.




<!DOCTYPE HTML>
< html >
< head >
< title >
Remove the “No file chosen” from a file input in Chrome?
</ title >
< style >
.removeValue {
color: transparent;
}
</ style >
< script src =
</ script >
</ head >
< body style = "text-align:center;"
id = "body" >
< h1 style = "color:green;" >
GeeksForGeeks
</ h1 >
< p id = "GFG_UP"
style="font-size: 15px;
font-weight: bold;">
</ p >
< div >
< input type = "file" />
</ div >
< br >
< button onclick = "gfg_Run()" >
Remove value
</ button >
< p id = "GFG_DOWN"
style="color:green;
font-size: 20px;
font-weight: bold;">
</ p >
< script >
var el_up = document.getElementById("GFG_UP");
var el_down = document.getElementById("GFG_DOWN");
el_up.innerHTML =
"Click on the button to remove the value '" +
"No file is chosen.'";
function gfg_Run() {
$('input').addClass('removeValue');
el_down.innerHTML = "Value has been removed.";
}
</ script >
</ body >
</ html >

Выход:

  • Перед нажатием на кнопку:
  • После нажатия на кнопку: