1
我想知道如何在選擇輸入時使用javascript/html(表單驗證)來限制輸入的數量。情景:我首先有一個下拉框,您可以選擇您的國家代碼以獲取手機號碼;一旦選擇,當然必須輸入他們的手機號碼(手機號碼的長度取決於你選擇的國家代碼,例如+63 [菲律賓],用戶手機號碼只能有11個字符長)。以下是我的代碼行:當在選擇下拉列表中選擇時,限制表單中的輸入數
<div class="input-append">
<select name="mobile" tabindex="15" style="height: 30px; width: 80px;" required>
<option <?php if (isset($source) && $source=="Philippines") ?>>+63 (Philippines)</option>
<option <?php if (isset($source) && $source=="America") ?>>+1 (America)</option>
<option <?php if (isset($source) && $source=="UK") ?>>+44 (United Kingdom)</option>
<option <?php if (isset($source) && $source=="Japan") ?>>+81 (Japan)</option>
<option <?php if (isset($source) && $source=="Korea") ?>>+82 (Korea)</option>
<option <?php if (isset($source) && $source=="China") ?>>+86 (China)</option>
</select>
<input type="number" name="mobile_phone" tabindex="16" style="height: 30px; width: 127px;" placeholder="Enter your Mobile Phone Number" maxlength="11"required>
</div>
謝謝你的迴應!
使用min和max屬性檢查這個http://www.wufoo.com/html5/attributes/04-minmaxstep.html – Choco 2014-10-31 10:08:33
使用javascript的onchange事件。 – 2014-10-31 10:09:21
我不這麼認爲,這個設施與Javascript一起工作。因此,用戶Jquery而不是Javascript其他明智寫你自定義代碼作爲每個選項的價值。看到這個鏈接爲jquery示例:http://stackoverflow.com/questions/6141680/setting-maxlength-of-textbox-with-javascript-or-jquery – Hkachhia 2014-10-31 10:14:22