一个人如何用PHP回应这个jQuery [英] How would one echo this jQuery in PHP

查看:68
本文介绍了一个人如何用PHP回应这个jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

echo "<form class='noPrint' action='demo/saveToExcel.php' method='post' target='_blank'
       onsubmit='$('#datatodisplay').val( $('<div>').append( $('#dataTable').eq(0).clone() ).html() )'>
       <pre><input id='excel' type='image' src='img/file.png'></pre>
       <p id='save'>Save table data to Excel</p>
       <pre><input type='hidden' id='datatodisplay' name='datatodisplay' />
       </form>
       <input class='noPrint' type='button' id='print' value='Print' />";

运行页面时,没有出现解析错误,但是').append( $('#dataTable').eq(0).clone() ).html() )'>实际上显示在页面上,因此jQuery无法正常工作!

When i run the page, i dont get a parse error, however ').append( $('#dataTable').eq(0).clone() ).html() )'> actually shows on the page, therefore the jQuery doesn't work!

如何将其正确包含在回声中?

How can i include it in the echo correctly?

谢谢

推荐答案

为什么不完全跳过echo呢?

 //your PHP code before this echo statement

 //let us say this is part of a IF statement

 if(true)
 {
 ?>

 <form class='noPrint' action='demo/saveToExcel.php' method='post' target='_blank'
   onsubmit="$('#datatodisplay').val( $('<div>').append( $('#dataTable').eq(0).clone() ).html() )">
   <pre><input id='excel' type='image' src='img/file.png'></pre>
   <p id='save'>Save table data to Excel</p>
   <pre><input type='hidden' id='datatodisplay' name='datatodisplay' />
   </form>
   <input class='noPrint' type='button' id='print' value='Print' />

 <?php

 } //if ends here
 // continue with your PHP code

编辑:onsubmit中的嵌套引号字符也不正确.上面给出的代码还通过将这些引号转换为双引号来解决了该问题.

EDIT: You also have a improperly nested quote characters in onsubmit. The code given above ALSO fixes that by converting those quotes to double quotes.

您还可以使用echo并像这样转义那些引号:

You can also use echo and escape those quotes like this:

  echo "<form class='noPrint' action='demo/saveToExcel.php' method='post' target='_blank'
   onsubmit=\"$('#datatodisplay').val( $('<div>').append( $('#dataTable').eq(0).clone() ).html() )\">
   <pre><input id='excel' type='image' src='img/file.png'></pre>
   <p id='save'>Save table data to Excel</p>
   <pre><input type='hidden' id='datatodisplay' name='datatodisplay' />
   </form>
   <input class='noPrint' type='button' id='print' value='Print' />";

这篇关于一个人如何用PHP回应这个jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆