博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
添加或删除项并动态记录项的值
阅读量:5352 次
发布时间:2019-06-15

本文共 1976 字,大约阅读时间需要 6 分钟。

JS方法

        function addSelCont() {

            var provinceObj = $('#<%=ddlarea.ClientID %>');
            var cityObj = $('#<%=ddlarea2.ClientID %>');
            var provinceId =provinceObj.val();
            var cityId = cityObj.val();
            var provincetName = provinceObj.find("option:selected").text();
            var cityName = cityObj.find("option:selected").text();
            if (cityId =='') cityName = '';
            if (provinceId !='') {
                $('#selcont').append(
                $('#hidformat').html().format(provincetName, cityName,provinceId,cityId)
            );
                var selObj = $('#<%=hidSelAreaval.ClientID %>');
                var newval = selObj.val();
                if (selObj.val() != '') newval += ',';
 
                selObj.val(newval + provinceId + '|' + cityId);
            }
        }
        function selAreaRemove(provinceId, cityId, obj) {
      
            var selObj = $('#<%=hidSelAreaval.ClientID %>');
            var re = ',' + provinceId + '\|' + cityId + ',';
            var newval = (',' + selObj.val() + ',').replace(re, ',');
            newval = newval.replace(/^,+|,+$/g, '');
            selObj.val(newval);
 
            $(obj).parent().remove();

        }

ASPX页面

                        <div id="hidformat" style="display:none">

                                         <div class="sel_area">{0}&nbsp;{1}<span οnclick="selAreaRemove('{2}','{3}',this)"></span></div>
                                    </div>
                                    <div class="item">
                                        <div style="float: left">
                                            我已经选择了:</div>
                                        <div id="selcont"></div>
                                    </div>
                                    <div class="item">
                                        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                            <ContentTemplate>
                                        <asp:DropDownList ID="ddlarea" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlarea_SelectedIndexChanged">
                                        </asp:DropDownList>
                                        <asp:DropDownList ID="ddlarea2" runat="server">
                                                <asp:ListItem Value="0">城市</asp:ListItem>
                                        </asp:DropDownList>
                                        <span class="ai_item_sub" οnclick="addSelCont()" style=" cursor:pointer">增加</span>
                                              </ContentTemplate>
                                         </asp:UpdatePanel>
                                        <asp:HiddenField ID="hidSelAreaval" runat="server" Value="" />
                                    </div>

CSS样式

 .sel_area {

    background: url(../images/ai_05.png) no-repeat right center;
    float: left;
    margin-left:20px;
}
 .sel_area span{
    cursor: pointer;
    display: inline-block;
    width:10px;
    height:10px;
    vertical-align: middle;
    margin-left:2px;
}

转载于:https://www.cnblogs.com/dashi/p/4034650.html

你可能感兴趣的文章
【Qt】Qt Linguist介绍【转】
查看>>
sim usim Uim 区别
查看>>
网页中插入透明Flash的方法和技巧
查看>>
动态内存申请函数选择(realloc、malloc 、alloca、 calloc)
查看>>
获取元素属性get_attribute
查看>>
视觉设计师的进化
查看>>
Python/jquery
查看>>
WPF之Binding
查看>>
【BZOJ】【2132】圈地计划
查看>>
Lua 语言基本语法
查看>>
ARM 的Thumb状态测试
查看>>
windows下读取utf-8文件
查看>>
apache 启动不了的排查方法
查看>>
Java有没有goto?
查看>>
(转)makefile 的用法
查看>>
求不相邻金币相加和的最大值--动态规划1
查看>>
[转][osg]探索未知种族之osg类生物【目录】
查看>>
四十九. Zabbix报警机制 、 Zabbix进阶操作 、 监控案例
查看>>
元类中__new__ 与 __init__的区别--day27
查看>>
占小狼的简书博客
查看>>