2012-05-02 89 views

回答

7

使用jQuery的代碼和以下點擊功能,這將有助於

$(document).ready(function() 
{ 
    $('#slectboxid option').click(function() 
    { 
     var items = $(this).parent().val(); 
     if (items.length > 3) { 
         alert("You can only select 3 values at a time"); 
      $(this).removeAttr("selected"); 
     } 
    }); 
    }); 

編輯:使用.prop()代替.removeAttr().removeAttr()中棄用最新的jQuery庫

+0

我編輯的代碼,它完美 – nu6A

+0

我會去的jQuery的解決方案也爲更好的用戶體驗,但不要忘記在PHP中驗證(如果javascript被禁用) –

+0

是的,服務器端驗證是必須的。我同意你mr.claarman – nu6A

3

formsubmit.php變線3以下行:

if (isset($options) && count($options) == 3) { 

然後修改線26以下:

echo 'Please select exactly 3 options'; 
相關問題