将想法与焦点和您一起共享

网站开发中jQuery操作select 的option发布者:本站     时间:2020-05-16 08:05:12

jQuery操作select 的option

$(function(){
           $("#addip").click(function(){
                                      var $beginip1=$("#s_ip_1").val();
                                      var $beginip2=$("#s_ip_2").val();
                                      var $beginip3=$("#s_ip_3").val();
                                      var $beginip4=$("#s_ip_4").val();
                                      var $endip1=$("#e_ip_1").val();
                                      var $endip2=$("#e_ip_2").val();
                                      var $endip3=$("#e_ip_3").val();
                                      var $endip4=$("#e_ip_4").val();
                                      var $beginip=$beginip1+"."+$beginip2+"."+$beginip3+"."+$beginip4;
                                      var $endip=$endip1+"."+$endip2+"."+$endip3+"."+$endip4;
                                      //检查IP段
                                      if($beginip1>$endip1){
                                          alert("起始IP不能大于结束IP地址");
                                      }
                                      //验证数据库是否存在
                                     
                                      //添加到select的选项
                                      if($("#ip_type:checked").val()=="1"){
                                          //IP段
                                          $("#limit_ip_list").append("<option value='"+$beginip+"~"+$endip+"'>"+$beginip+"~"+$endip+"</option>");
                                      }else{
                                          $("#limit_ip_list").append("<option value='"+$beginip+"'>"+$beginip+"</option>");
                                      }
                                      });
});
 

 

<table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td colspan="2"><input type="radio" name="ip_type" id="ip_type" value="1" checked="checked"/>
            IP段
            <input type="radio" name="ip_type" id="ip_type" value="0" />
            IP值</td>
          <td>被限制的IP列表</td>
          <td></td>
        </tr>
        <tr>
          <td><input name="s_ip_1" id="s_ip_1" type="text" size="4" value="192">
            .
            <input name="s_ip_2" id="s_ip_2"  type="text" size="4" value="168"/>
            .
            <input name="s_ip_3" id="s_ip_3"  type="text" size="4" value="0"/>
            .
            <input name="s_ip_4" id="s_ip_4"  type="text" size="4" value="0"/></td>
          <td rowspan="3"><input type="button" name="addip" id="addip" value="=>" /></td>
          <td rowspan="3"><select style="width:230px" size="5" multiple="multiple" id="limit_ip_list" name="limit_ip_list">
              <option value="192.168.1.0~192.168.1.255">192.168.1.0~192.168.1.255</option>
              <option value="192.168.0.100">192.168.0.100</option>
            </select></td>
          <td rowspan="3"> 可双击删除<br />
            <input type="button" name="delip" id="delip" value="删除选择" /></td>
        </tr>
        <tr>
          <td align="center" bgcolor="#FFFFFF">~</td>
          <td></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF"><input name="e_ip_1" id="e_ip_1"  type="text" size="4" value="192">
            .
            <input name="e_ip_2" id="e_ip_2" type="text" size="4" value="168"/>
            .
            <input name="e_ip_3" id="e_ip_3" type="text" size="4" value="0"/>
            .
            <input name="e_ip_4" id="e_ip_4" type="text" size="4" value="0"/></td>
          <td></td>
        </tr>
      </table>



选择我们,优质服务,不容错过
1. 优秀的网络资源,强大的网站优化技术,稳定的网站和速度保证
2. 15年上海网站建设经验,优秀的技术和设计水平,更放心
3. 全程省心服务,不必担心自己不懂网络,更省心。
------------------------------------------------------------
24小时联系电话:021-58370032