根据输入字段更改文本并根据单选按钮禁用输入

发布于 2024-12-19 17:38:45 字数 2331 浏览 1 评论 0原文

我需要根据输入字段中输入的“年份”更改输入之前的文本, 更改“显示年份”时,禁用不必要的收入/资产字段。

<!DOCTYPE html>
<html>
<head>
    <title>title</title>
    <script type="text/javascript">
        window.onload=function() {
            // On "year" change, validate it and cahnge the text befor the input fields.
            var year = document.getElementsByName("year");
            year.onclick=function() {
                this.year0_text.value = year[this.value];
                this.year1_text.value = year[this.value]+1;
                this.year2_text.value = year[this.value]+2;
            }

            // and on "years" change, disable the unnecessary income/assets fields.
        }
    </script>
</head>
<body>
    <form name="ar" action="." method="post">
        Year:<br />
        <input type="number" name="year" value="2011"><br />
        <br />
        Years to Show:<br />
        <input type="radio" name="years" value="0.5">first period (not full year)<br />
        <input type="radio" name="years" value="1">1 year<br />
        <input type="radio" name="years" value="2">2 years<br />
        <input type="radio" name="years" value="3">3 years<br />
        <br />
        Income:<br />
        <span class="year0_text">20XX-0</span> <input type="number" name="year0_income" value="0"><br />
        <span class="year1_text">20XX-1</span> <input type="number" name="year1_income" value="0"><br />
        <span class="year2_text">20XX-2</span> <input type="number" name="year2_income" value="0"><br />
        <br />
        Assets:<br />
        <span class="year0_text">20XX-0</span> <input type="number" name="year0_assets" value="0"><br />
        <span class="year1_text">20XX-1</span> <input type="number" name="year1_assets" value="0"><br />
        <span class="year2_text">20XX-2</span> <input type="number" name="year2_assets" value="0"><br />
    </form>
</body>
</html>

演示 - http://jsfiddle.net/92GaE/2/

I need to change the text before the input based on "year" entered on the input field,
and when changing the "Years to Show", disable the unnecessary income/assets fields.

<!DOCTYPE html>
<html>
<head>
    <title>title</title>
    <script type="text/javascript">
        window.onload=function() {
            // On "year" change, validate it and cahnge the text befor the input fields.
            var year = document.getElementsByName("year");
            year.onclick=function() {
                this.year0_text.value = year[this.value];
                this.year1_text.value = year[this.value]+1;
                this.year2_text.value = year[this.value]+2;
            }

            // and on "years" change, disable the unnecessary income/assets fields.
        }
    </script>
</head>
<body>
    <form name="ar" action="." method="post">
        Year:<br />
        <input type="number" name="year" value="2011"><br />
        <br />
        Years to Show:<br />
        <input type="radio" name="years" value="0.5">first period (not full year)<br />
        <input type="radio" name="years" value="1">1 year<br />
        <input type="radio" name="years" value="2">2 years<br />
        <input type="radio" name="years" value="3">3 years<br />
        <br />
        Income:<br />
        <span class="year0_text">20XX-0</span> <input type="number" name="year0_income" value="0"><br />
        <span class="year1_text">20XX-1</span> <input type="number" name="year1_income" value="0"><br />
        <span class="year2_text">20XX-2</span> <input type="number" name="year2_income" value="0"><br />
        <br />
        Assets:<br />
        <span class="year0_text">20XX-0</span> <input type="number" name="year0_assets" value="0"><br />
        <span class="year1_text">20XX-1</span> <input type="number" name="year1_assets" value="0"><br />
        <span class="year2_text">20XX-2</span> <input type="number" name="year2_assets" value="0"><br />
    </form>
</body>
</html>

DEMO - http://jsfiddle.net/92GaE/2/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

長街聽風 2024-12-26 17:38:45

拉米怎么了? (ma kore?)

只需添加一个事件监听器,您可能想看看这个:
事件监听器

Whats up rami? (ma kore?)

Just add an event listener, you may want to take a look at this for instance:
Event Listeners

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文