[-][input][+]

http://api.jquery.com/on/

http://api.jquery.com/prev/

 

tip: adding the jqm will wrap the input tab, & prev() doesn't work. add "data-role='none' " in input.

 

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
 5 <script src="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script>
 6 <script>
 7 $().ready(function(){
 8     var max = 7;
 9     $("#stationinfo").on("click",".J_add",function(){
10         var t = $(this).prev(".J_input");
11         if(Number(t.val())< Number(max))
12         {
13             t.val(parseInt(t.val())+1);
14         }                
15     });
16     
17     $("#stationinfo").on("click",".J_minus",function(){
18         var t = $(this).next(".J_input");
19         if(Number(t.val())>0){
20             t.val(parseInt(t.val())-1);
21         }                
22     });
23 });
24 </script>
25 </head>
26 <body>
27     <div id="stationinfo">
28         <a href='javascript:;' class='J_minus'>-</a>
29         <input type='text' class='J_input' value='0' data-role='none'/>
30         <a href='javascript:;' class='J_add'>+</a>
31     </div>
32 </body>
33 </html>
View Code

 

posted @ 2014-07-05 12:42  小王子2013  阅读(262)  评论(0编辑  收藏  举报