2016-06-14 56 views
1

我想要使用jquery插件來處理IPV4地址。插件可在https://github.com/felipevolpatto/jquery-input-ip-address-controljquery插件輸入字段接受多個IP地址

問題是我只能使用一個文本字段的IPV4地址。如果我再使用一個,我只能看到沒有任何分隔符的普通文本字段。如何將它用於IPV4地址的多個文本字段?

代碼:

<form role="form"> 

        <div class="form-group"> 
          <label>Starting Address</label></br>       
          <input type="text" name="ip1" id="ipv4"> 

         </div> 
         <div class="form-group">         
          <label>Ending Address</label></br>       
          <input type="text" name="ip2" id="ipv4"> 
         </div>  


</form>  
<script src="js/jquery.input-ip-address-control-1.0.min.js"></script> 
<script> 
    $(function(){ 
     $('#ipv4').ipAddress(); 
    }); 
</script> 

回答

0

在這種情況下,您不能使用相同的ID。更改id="ipv4"class="ipv4",並嘗試

$(function(){ 
     $('.ipv4').ipAddress(); 
    }); 
1

id是全局唯一標識符。它應該只用於頁面上的單個元素。如果重複相同的id,通常只選擇第一個,但這可能會有所不同,並且您不應該這樣做。如果你想把ipv4應用到另一個元素,你應該把它作爲一個類。

class="ipv4"

並更改jQuery來反映:

$(function(){ 
    $('.ipv4').ipAddress(); 
}); 

https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id