下拉列表中的值

Values in dropdown list

下面是我在网上找到的一个工作示例,希望使用非常相似的东西。

如何从同一选择的下拉列表中显示 2 种不同的价格和货币,而无需为每个 currency/price 进行多次下拉? 据我所知,您只能将下拉列表中的值保存为 mysql(本例中的价格值)我想保存所选名称而不是 currency/price.. 或如果可能的话,两者都可以吗?

<select id="bedrooms" onchange="changeddl(this)">
          <option>Choose beds</option>
          <option value="150">1 bed</option>
          <option value="200">2 beds</option>
          <option value="300">3 beds</option>
          <option value="400">4 beds</option>
        </select>

        <div id="divprice"></div>

        function changeddl($this){
           $("#divprice").text($this.value>0?("price: $ " + $this.value):"");
        };

为什么不试试下拉列表呢?然后,您可以使用 trim 函数将变量设置为等于用户在下拉列表中的选择。这是一个例子:

<td><asp:DropDownList ID ="BedroomsDropDown" runat="server" Width="75px"
                        >
                    <asp:ListItem></asp:ListItem>
                    <asp:ListItem>0, 1 bed</asp:ListItem>
                    <asp:ListItem>0, 2 beds</asp:ListItem>
                    <asp:ListItem>0, 3 beds</asp:ListItem>
                    <asp:ListItem>0, 4 beds</asp:ListItem>
                    </asp:DropDownList></td>

然后你可以将用户输入保存到一个变量中:

BEDS = BedroomsDropDown.Text.Trim();

只需确保使用由另一个操作调用的方法(按钮效果很好)来保存用户输入。如果需要,我可以为此提供示例代码。当输入被保存到一个变量中时,它可以根据您需要的任何目的进行操作。

试试这个来显示名称和价格

function changeddl($this){ var item = $('#bedrooms option:selected').text() $("#divprice").text($this.value>0?(item +"- price: $ " + $this.value):""); };

至于 select 货币,我建议您使用不同的下拉列表,让用户 select 首选货币