0

我正在使用 SQL Server 实现地理位置表。
我在数据库中添加了主要国家、州和城市,但我想通过在下拉菜单中选择“其他”选项来允许添加值。如果我在国家/地区选择“其他”,则应在州和城市下拉列表中选择相同的选项。它还应该为每个下拉菜单显示额外的文本框。
我正在使用 asp.net 3.5,数据库是使用 linq 的 sql server 2008。请帮忙!!

4

2 回答 2

0
 $('#states').change(function() {
    alert('Handler for .change() called.');
    var value = $(this).val();
       if(value == '')
       {
         // change other city drop down 
         var newOption = $('<option value="">Other</option>');
         $('#city').append(newOption);
       }
 });
于 2012-07-28T11:35:55.003 回答
0

用数据库中的值填充下拉列表后,您应该再添加一个:'Other...' 和 'other' 的值,它应该放在列表的末尾。
此外,您应该为每个下拉菜单放置一个隐藏的文本框:

<asp:TextBox ID="txtState" runat="server" Style="display:none;"></asp:TextBox>

在客户端,您可以使用 jQuery 或 javascript 来捕捉用户何时选择此值。应该有三个功能:“其他国家”显示所有三个文本框,“其他州”显示两个,“其他城市”仅显示一个:

$('#countries').change(function() {
    var country= $("#states option:selected").text();
    if(country == 'other') {
        var country = $("#countries option:selected").val();
    if (country === 'other') {
        $("#states").val('other');
        $("#cities").val('other');

        $("#txtCountry").show();
        $("#txtState").show();
        $("#txtCity").show();
   }
   else {
       //if user select 'other' and later select something else, you should hide textbox
       $("#txtCountry").hide();
   }

});

以同样的方式,为州和城市创建函数。

在此之后,您可以在后面的代码中检查所选值是否为“其他”,然后使用文本框中的值。我希望你能明白。

于 2012-07-28T12:39:02.190 回答