使用 jQuery 更改基于下拉 html 数组的文本框

Changing a textbox based on a dropdown html array with jQuery

本文关键字:数组 文本 html 于下拉 jQuery 使用      更新时间:2023-09-26

所以我发现这样做的问题,我很好奇是否因为我使用的是 HTML 表单数组。

无论如何,这是我的问题,我想更改一个下拉框并让它将文本框中的文本更改为该值!声音很简单吧?

好吧,这是我失败的尝试:

<select id=discount[0] name=discount[0]>
    <option value=1>option 1</option>
    <option value=2>option 2</option>
</select>
<input type=text id=postdiscount[0]>

和我的JS:

$("#discount[0]").change(function () {
        $("#postdiscount[0]").val(this.value);
});

JSFiddle,如果你们想玩:http://jsfiddle.net/t75ut97f/3/

编辑:与表单项在数组中无关:X!

您需要转义括号,然后只需使用this.value

$("#discount''[0'']").change(function () {
    $("#postdiscount''[0'']").val(this.value);
});

http://jsfiddle.net/t75ut97f/2/