-1

input type=text と input type=file (私の場合は Title と File) の HTML フォームがあります。誰かがファイルを選択したときに、Title の値を変更したいと思います。私はJavascriptを試しましたが、私は解決策に近づいていません.

4

4 に答える 4

1

非常に単純です。.change()イベントがそのトリックを行います。

<input type="text" id="title"/>
<input type="file" id="file"/> 

$("#file").change(function() {
    $("#title").val("Changed!");
});

デモ: http://jsfiddle.net/FkJss/

于 2013-05-29T16:45:05.200 に答える
1

このようにしてみてください:

$("input:file").change(function () {
    $("#idtexbox").val('DesiredValue');

    $("input:file").val("");//clear file input value
});

デモ

于 2013-05-29T16:45:46.370 に答える
0

jQuery.change() を試すことができます:

$(file_selector).change(function (){
  $(title_selector).val(value_to_change);
});
于 2013-05-29T16:46:13.667 に答える
0

jQuery を使用したくない場合は、次のようにします。

document.getElementByID("file").onchange(function(){
    document.getElementByID("title").value("Changed!");
});
于 2013-05-29T16:49:05.810 に答える