-1

我正在尝试通过以下代码传递价值,但无法请任何人检查,也许我在某个地方弄错了

<input type="button" name="vote" value="Yes" width="100" onclick="getVote('; echo "y".$info['autoid']; echo')"/>

问题出在以下行“y”.$info['autoid']; 如果我删除“y”。它工作正常。但我想传递 y 和产品 ID。

基本上我正在尝试将 y 与 int 结合起来。

好的,这里是完整的代码。

 <script type="text/javascript">

  function getVote(int)
  {
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
       xmlhttp.onreadystatechange=function()
         {
         if (xmlhttp.readyState==4 && xmlhttp.status==200)
         {
      document.getElementById("poll").innerHTML=xmlhttp.responseText;
           }
    }
 xmlhttp.open("GET","../poll/"+int,true);
xmlhttp.send();
}
</script>


<div id="poll">
 <form>
poll - :
<input type="button" name="vote" value="Yes" width="100" onclick="getVote('; echo     "y".$info['autoid']; echo')"/>
<input type="button" name="vote" value="No" width="100" onclick="getVote('; echo   "n".$info['autoid']; echo')"/>
</form>
 </div>

谢谢大家...我找到了另一种方式,我们可以通过“-”表示是,而为“n”则为空

<input type="button" name="vote" value="Yes" width="100" onclick="getVote('; echo "-".$info['autoid']; echo')"/>
<input type="button" name="vote" value="No" width="100" onclick="getVote('; echo $info['autoid']; echo')"/>
4

3 回答 3

1

您试图在双引号中包含双引号,但不清楚您的 php 包装器在哪里?

我将 onclick 属性重写为:

onclick="getvote( <?php echo "y{$info['autoid']}"?> "
于 2012-08-13T20:52:18.237 回答
0

您的代码在问题所在的位置有点混乱。

用这个:

<input type="button" name="vote" value="Yes" width="100" onclick="getVote('y<?php echo $info['autoid']; ?>');"/>
于 2012-08-13T21:09:27.727 回答
0

int 是 javascript 中的保留字,您也应该使用 JQuery 之类的东西来处理您的 ajax 调用。

于 2012-08-13T21:02:44.090 回答