2015-05-20 41 views
0

我使用iCheck創建了現代單選按鈕,並且有四個選項。當用戶改變單選按鈕時,我彈出確認消息「你確定嗎?」帶iCheck的單選按鈕僅在確認返回true時更改值

如果確認返回false,我想返回上一個單選按鈕,但現在它不回到以前的收音機。

這是部分代碼:

<form action="#" method="post"> 
    <div style="padding-left:20px; line-height:2;"> 
     <input type="radio" id="main-category1" name="main-category" value="1" > 1. <br> 
     <input type="radio" id="main-category2" name="main-category" value="2" > 2. <br> 
     <input type="radio" id="main-category3" name="main-category" value="3" > 3. <br> 
     <input type="radio" id="main-category4" name="main-category" value="4" > 4. <br> 
     <input type="radio" id="main-category5" name="main-category" value="5" > 5. <br> 
    </div> 
    </form> 

<scirpt> 
$('input').on('ifClicked', function(event){   
    msg = confirm('Are you sure?'); 
    var cual= this; 
    if(msg == false) { 
     $('#main-category3').iCheck('check'); // It's check to new value and check to 3rd radio, but I want to check only 3rd radio. 
    } 
}); 
</script> 
+1

如果加上'返回FALSE'會發生什麼? –

+0

@JamesDonnelly; add return false - >它不會發生 – punny

回答

0
<script> 
    $('input').on('click', function(event) { 
     msg = confirm('Are you sure?'); 
     var cual = this; 
     if (msg == false) { 
     $('#main-category3').attr("checked",true); 
     // It's check to new value and check to 3rd radio, but I want to check only 3rd radio. 
     } 
    }); 
    </script> 

我創建了一個普拉克爲您的代碼,並提出了整改

http://plnkr.co/edit/gist:1986619?p=preview

+1

'ifClicked'是iCheck插件中的有效事件。 –

+0

@JamesDonnelly謝謝你的信息。欣賞它。普朗克沒有提到它。我現在添加它。 – kanchirk

+0

@kanchirk謝謝 – punny

相關問題