【发布时间】:2015-12-01 03:49:56
【问题描述】:
我尝试通过 Php echo 向 div 附加一些内容
包括
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
PHP 代码
<?php echo "<script type='text/javascript' >$('.notificationsBody').prepend('Hello World');</script>"; ?>
我的分区代码
<div class="notificationsBody">TESTING DIV<br></div>
这可能吗?如果是,为什么这不起作用?我的控制台也是空的。 如果没有,还有其他方法可以实现在 Php Echo 上附加 Div 吗?
提示:如果可能的话,我需要一个 PHP 回显。
这是我完整的 index.php 页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<?php echo "<script type='text/javascript' >$('.notificationsBody').prepend('Hello World');</script>"; ?>
<div class="notificationsBody">TESTING DIV<br></div>
</body>
</html>
最后我想要的是你有一个类并调用函数
<?php echo $myclass->theechofunction(); ?>
然后这将回显将 Div 附加到我的 Wrapper 的 Javascript。
是的,它有点疯狂/困难,但这就是我需要的。
感谢您的每一个回答。
编辑
调用站点后的站点 Quellcode
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type='text/javascript' >$('.notificationsBody').prepend('Hello World');</script>
<div class="notificationsBody">TESTING DIV<br></div>
【问题讨论】:
-
为什么需要 PHP 回显?
-
看起来你在页面加载之前运行它learn.jquery.com/using-jquery-core/document-ready
-
我目前正在测试一些东西 :) 我需要 PHP 回显
-
你能解释一下你的最终意图吗,因为你给出的例子很奇怪。
-
请在问题中显示输出的 HTML
标签: javascript php jquery html