php echo中的javascript代码
这是我用HTML编写的功能性onClick脚本,它可以完美地工作:php echo中的javascript代码,javascript,php,html,Javascript,Php,Html,这是我用HTML编写的功能性onClick脚本,它可以完美地工作: <input type="text" id="t" name="t" value="1"> <a href="testar.php?action=" onclick="window.location=this.href+'&quant='+document.getElementById('t').value;return false;">Click</a> 我想要实现的是: ec
<input type="text" id="t" name="t" value="1">
<a href="testar.php?action=" onclick="window.location=this.href+'&quant='+document.getElementById('t').value;return false;">Click</a>
我想要实现的是:
echo '<input type="text" value="1" id="t" name=""/>
<a href="addCarrinho.php?id_produto='.$registo['id'].'&nome='.$registo['nome'].'&preco='.$registo['preco'].'" onclick="window.location=this.href+'&quant='+document.getElementById('t').value;return false;">Add</a>';
echo'
';
所有的php都可以工作,我在另一个页面上接收到php变量,但是onClick javaScript不工作,我收到一个sintaxe错误。
我认为这是一个引号问题,但我不熟悉javaScript。改为:
<a href="addCarrinho.php?id_produto='.$registo['id'].'&nome='.$registo['nome'].'&preco='.$registo['preco'].'" onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;">Add</a>';
...
onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;"
...
”;
更改为以下内容:
<a href="addCarrinho.php?id_produto='.$registo['id'].'&nome='.$registo['nome'].'&preco='.$registo['preco'].'" onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;">Add</a>';
...
onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;"
...
”;
更改为以下内容:
<a href="addCarrinho.php?id_produto='.$registo['id'].'&nome='.$registo['nome'].'&preco='.$registo['preco'].'" onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;">Add</a>';
...
onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;"
...
”;
更改为以下内容:
<a href="addCarrinho.php?id_produto='.$registo['id'].'&nome='.$registo['nome'].'&preco='.$registo['preco'].'" onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;">Add</a>';
...
onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;"
...
”;
您需要对最后一行中的单引号进行转义,如下所示:
<a href="addCarrinho.php?id_produto='.$registo['id'].'&nome='.$registo['nome'].'&preco='.$registo['preco'].'" onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;">Add</a>';
...
onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;"
...
您需要对最后一行中的单引号进行转义,如下所示:
<a href="addCarrinho.php?id_produto='.$registo['id'].'&nome='.$registo['nome'].'&preco='.$registo['preco'].'" onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;">Add</a>';
...
onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;"
...
您需要对最后一行中的单引号进行转义,如下所示:
<a href="addCarrinho.php?id_produto='.$registo['id'].'&nome='.$registo['nome'].'&preco='.$registo['preco'].'" onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;">Add</a>';
...
onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;"
...
您需要对最后一行中的单引号进行转义,如下所示:
<a href="addCarrinho.php?id_produto='.$registo['id'].'&nome='.$registo['nome'].'&preco='.$registo['preco'].'" onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;">Add</a>';
...
onclick="window.location=this.href+\'&quant=\'+document.getElementById(\'t\').value;return false;"
...
echo'
';
试着用这种方法,我做了一些单引号和双引号的更改。echo'
';
试着用这种方法,我做了一些单引号和双引号的更改。echo'
';
试着用这种方法,我做了一些单引号和双引号的更改。echo'
';
这样试试看,我做了一些单引号和双引号的更改。问题中突出显示的语法向您显示问题-使用反斜杠将单引号转义问题中突出显示的语法向您显示问题-使用反斜杠将单引号转义问题中突出显示的语法向您显示问题-转义使用反斜杠将单引号引到此处问题中突出显示的语法将向您显示问题-使用反斜杠将单引号转义到此处