无法通过jquery提交post变量,输入为image

时间:2012-04-29 12:38:43

标签: php html jquery-plugins

我想编写一个插件,它会在点击输入图像或任何其他方法时将存储为输入(即图像)id的变量传递给表单

=============================================== ==========================================

<?php
echo $_POST['id'];
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kunfu Panda</title>
<link href="css/main.css" rel="stylesheet" type="text/css" media="projection,screen" />
</head>
<body>
    <div class="wrapper" >
        <form action="panda.php" method="post" class="openid_provider" />
             <input type="image" src="images/google_button.png" id="google" /> 
         </form>    
  </div>
<script type="text/javascript" src="js/test.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.19.custom.min.js"></script>
<script type="text/javascript">  
$(document).ready(function(){
    $('form').openid(); 
})
</script>
</body>
</html>

=============================================== ================================

我的插件是openid(test,js)

(function($){
    $.fn.openid = function() {
        $('input').click(function(){
        var provider = $(this).attr('name');
        $(this).submit(provider);   
        })
        }
})(jQuery);

现在表单是在点击谷歌图片上提交的,这是一个id为“google”的输入,但是同一页面的表单操作无法识别$ _POST ['provider']变量

请帮帮我。

1 个答案:

答案 0 :(得分:0)

试试这个:

<?php
  var_dump($_POST);
?>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Kunfu Panda</title>
  <link href="css/main.css" rel="stylesheet" type="text/css" media="projection,screen" />
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js"></script>
  <script type="text/javascript" src="js/test.js"></script>
</head>
<body>
  <div class="wrapper" >
    <form action="panda.php" method="post" class="openid_provider" />
      <input type="image" src="images/google_button.png" id="google"/> 
    </form>
  </div>
</body>
<script type="text/javascript">  
  $(document).ready(function(){
    $('form').openid(); 
  })
</script>

JS:

(function($){
  $.fn.openid = function() {
    $('input').click(function(e){
      var provider = $(this).attr('id');  //get id
      var myinput = $('<input type="hidden" name="provider"/>').val(provider);
      $('form').append(myinput);
      $('form').submit();
    })
  }
})(jQuery);