基于jquery实现发送文章到手机的代码

前段时间做项目的时候写的一段代码,感觉挺实用,记录下来分享给大家


<a class="btn_fankui relative" id="btn_fankui" style="top:7px;">

        <div class="qr_content" id="fankui_1" style="top:40px; left:-25px;">

         <span></span>

         <form class="fankui_form" action=""> 

                <table>

    <caption>发送文章到手机</caption>

    

                 <tr>

                  <td align="right" valign="middle"><label for="mphno">手机号</label></td>

                   <td><input class="input" name="mphno" type="text" id="input_phone"/></td>

                  </tr>

      <tr id="p_memssage">

     

                  </tr>

                 <tr>

                   <td colspan="2" align="right" id="short_d"><input name="" type="button" class="fankui_tijiao" value="提&nbsp;交"/></td>

                   <td colspan="2" align="center" id="short_n" style="display:none">请稍等</td>

                  </tr>

                </table>

          </form>

        </div>

        </a>

   <script type="text/javascript">

                $("#btn_fankui").toggle(function(){

                    $("#fankui_1").fadeIn(1);},

                function(){

                    $("#fankui_1").fadeOut(1);});

                     $("#fankui_1").click(function(e){e.stopPropagation();});

    $(".fankui_tijiao").click(function(){

     var phone = $("#input_phone").val();

     var content = "您订阅的文章{$title}地址是:{$url}";

     var p1 = /^((\(\d{3}\))|(\d{3}\-))?13\d{9}|15\d{9}$/; 

     if (p1.test(phone)){

      $("#p_memssage").html("");

      $.ajax({

       url:"{APP_PATH}index.php?m=content&c=phone&a=sms",

       type:"POST",

       dataType:"html",

       data:{

        "id":"{$id}",

        "mobile":phone,

        "content":"您订阅的文章《{$title}》地址是:{$url}",

        "rip":"{php echo ip()}",

       },

       error:function(data1,data2){

        alert(data2);

        alert("提交出错!请稍后重试!");

       },

       beforeSend:function(){

        $("#short_d").hide();

        $("#short_n").css("display","block");

       },

       success:function(data){

        $("#fankui_1").css("display","none");

        $("#short_d").show();

        $("#short_n").css("display","none");

        alert(data);

       }

      });

       

     }else{

      $("#p_memssage").html("<td colspan='2'><center><font color='red'>请正确填写你的手机号</font></center></td>");

      return false;

     }

    });

    $("#fankui_2").click(function(){

     $(this).hide();

    })

            </script>