單選框radio改變事件詳解(用的jquery的radio的change事件)


單選框radio改變事件詳解(用的jquery的radio的change事件

一、總結

1、用的jquery的radio的change事件:當元素的值發生改變時,會發生 change 事件,radio選擇不同選項的時候恰巧是值發生改變。

 

 

二、單選框radio改變事件詳解

<input type="radio" name="bedStatus" id="allot" checked="checked" value="allot">Allot
<input type="radio" name="bedStatus" id="transfer" value="transfer">Transfer

 

 1 $(document).ready(function() {
 2     $('input[type=radio][name=bedStatus]').change(function() {
 3         if (this.value == 'allot') {
 4             alert("Allot Thai Gayo Bhai");
 5         }
 6         else if (this.value == 'transfer') {
 7             alert("Transfer Thai Gayo");
 8         }
 9     });
10 });

 

三、單選框選擇不同的選項登錄的賬號密碼自動改變

 

 

 1 <form class="am-form tpl-form-line-form" action="" method="post">
 2     
 3     <div class="am-form-group">
 4         <label class="am-radio-inline tpl-login-remember-me">
 5             <input class="tpl-form-input" type="radio" name="status" id="student" value="0" checked="checked">Student  6         </label>
 7         <label class="am-radio-inline tpl-login-remember-me">
 8             <input class="tpl-form-input" type="radio" name="status" id=teacher value="1" >Teacher  9         </label>
10     </div>
11 
12     <div class="am-form-group">
13         <input type="text" class="tpl-form-input" id="username" name="username" required="" value="" placeholder="username">
14 
15     </div>
16 
17     <div class="am-form-group">
18         <input type="password" class="tpl-form-input" id="password" name="password" required="" value="" placeholder="password">
19 
20     </div>
21 
22     <!-- 驗證碼 -->
23     <!-- <div class="am-form-group">
24         <input type="text" class="tpl-form-input" id="user-name" name="code" placeholder="CAPTCHA">
25     </div>
26     <div class="am-form-group">
27         <img width="100%" style="cursor: pointer" src="{:captcha_src()}" alt="captcha" onclick="this.src='{:captcha_src()}?'+Math.random();" />
28     </div> -->
29     <!--End 驗證碼 -->
30 
31 
32     <div class="am-form-group tpl-login-remember-me">
33         <input id="remember-me" type="checkbox">
34         <label for="remember-me">
35 
36             記住密碼
37         </label>
38         <label style="margin-left: 15px">
39             <a href="{:url('login/register')}">  注冊</a>
40         </label>
41 
42     </div> 
43 
44     <div class="am-form-group">
45 
46         <button type="submit" class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success  tpl-login-btn">提交</button>
47 
48     </div>
49 </form>

js

 1 <script>
 2     $(document).ready(function() {
 3         $('input[type=radio][name=status]').change(function() {
 4             if (this.value == '0') {
 5                 $("#username").val("student");
 6                 $("#password").val("student");
 7             }
 8             else if (this.value == '1') {
 9                 $("#username").val("teacher");
10                 $("#password").val("teacher");
11             }
12         });
13     });         
14 </script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM