根据另一个输入的值更改输入的值 [英] Changing input's value based on another input's value

查看:69
本文介绍了根据另一个输入的值更改输入的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有以下代码:

<input type="file" id="file" name="">
<input class="uploadarea">
<span class="button">Browse</span>

现在我已经设置了一些CSS来更改默认输入文件按钮的外观,现在的问题是,当我选择文件时,如何根据#file的值更改.uploadarea的值? /p>

我目前有此代码,但我不知道下一步该怎么做.

var x = document.getElementsByTagName('input');
inputfile = x[0];
textbox = x[1];

解决方案

添加onchange处理程序以处理文件事件上的change事件:

<input type="file" id="file" name="" onchange="something(this.value)">
<input id="somethinghere" class="uploadarea">
<span class="button">Browse</span>

function something(val) {
    document.getElementById('somethinghere').value = val;
}

您需要添加id属性才能使其正常工作

Let's say for example I have this code:

<input type="file" id="file" name="">
<input class="uploadarea">
<span class="button">Browse</span>

Now I've setupped some css to change the default input file button's look, And now the question is, How do i change .uploadarea's value depending on the value of #file when I select a file?

I currently have this code but I don't know what to do next.

var x = document.getElementsByTagName('input');
inputfile = x[0];
textbox = x[1];

解决方案

Add an onchange handler to handle the change event on the file event :

<input type="file" id="file" name="" onchange="something(this.value)">
<input id="somethinghere" class="uploadarea">
<span class="button">Browse</span>

function something(val) {
    document.getElementById('somethinghere').value = val;
}

You need to add the id attribute for this to work

这篇关于根据另一个输入的值更改输入的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆