使用jquery从显示页面上的php输出中获取信息

时间:2013-05-24 06:21:28

标签: php jquery mysql

好吧,基本上我有一个php页面,我们称之为form.php。此页面包含一个带有日期选择器,时间选择器和文本框的表单(input type =“date”input type =“time”input type =“textarea”)。当用户提交表单时,信息被发送到mysql数据库,并在下一页“display.php”上输出。

所有这一切都很好。 display.php页面由form.php中的代码构成 即。 <h1>This is the header</h1> <h2 class="date">$date</h2> <h3 class="time">$time</h3> <p class="message">$message</p>

display.php中的输出是


这是标题
2012-04-23
00:59
我的留言
一个按钮(目前仅检查我的工作)


我试图像这样使用jquery

$(document).ready(function(){ 
$('button').mousedown(function(){ 

if ($('h3').text() == "00:59") {
alert("Yup"); return true;}
 else { alert("Nope");return false;};
});
 });

这不符合时间,日期或消息。 如果我运行完全相同的代码,但搜索不是用变量创建的h1,那将起作用。

 $(document).ready(function(){ 
$('button').mousedown(function(){ 

if ($('h1').text() == "This is a header") {
alert("Yup"); return true;}
 else { alert("Nope");return false;};
});
 });

我无法弄清楚我在这里缺少什么。

我甚至可以将h1更改为00:59,运行jquery搜索h1 ==“00:59”,它将返回true并传递警报。

当我追踪从php变量创建的h2,h3和p元素时($ time,$ date,$ message)

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

尝试正确关闭<p>元素:

<h1>This is the header</h1>
<h2 class="date">$date</h2>
<h3 class="time">$time</h3>
<p class="message">$message</p>

答案 1 :(得分:0)

您是否检查过创建的h3是否包含任何编码或隐藏的字符?这可能会导致您的检查失败,因为您检查了您看到的文本,而不是标签中的实际文本。不要以为你使用的任何字符通常都是编码的,但值得一看。

jsfiddle中运行您的代码,因为它实际上包含正确的文本,它可以正常工作。因此,您检查的内容与标签中实际内容之间必定存在某种不匹配。

代码测试

HTML

<h1>This is the header</h1> <h2 class="date">2012-04-23</h2> <h3 class="time">00:59</h3> <p class="message">My message</p>
<button>Test</button>

的Javascript

$(document).ready(function(){ 
$('button').mousedown(function(){ 

if ($('h3').text() == "00:59") {
alert("Yup"); return true;}
 else { alert("Nope");return false;};
});
 });