javascript - 是否可以在 div 中打开包含外部 javascript 和 css 的页面?

标签 javascript php html

/* 我需要在一个包含 javascript 和 css 的 div 中打开一个网页。是否可以通过该页面加载该 javascript 和 css,或者我需要将该文件包含在父页面中?

例如:-

**Page1.php**

*/

    <!DOCTYPE html>
<html>
<head>
  <style>
  body{ font-size: 12px; font-family: Arial; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
 <b>Successful Response (should be blank):</b>
<a href="#" onclick="check();">click me</a>
<div id="success"></div>
<div id="b"></div>
<script>

function check(){
$('#b').load('test.php #target');
}
  </script>

</body>
</html>

//我需要在div中打开test.php

//test.php

<html>
<head></head>
<body>
<div id='target'>
<script type="text/javascript" src="script.js"></script>
 I am from test page. <a href="#" onClick="loaddata()">Click Here</a>
</div>
</body>
</html>

//在 test.php 中包含 script.js

//script.js

function loaddata()
{
    alert("hii");
}

//我的问题是这样做时 script.js 不工作

最佳答案

您的 page1.php 文件如下所示。您只需使用 include('myPhpPageName.php');在您的 php 标签内,这将包括 myPhpPageName.php 中的任何内容。查看下面的 test.php 以了解该页面需要什么。

    <!DOCTYPE html>
<html>
<head>
  <style>
  body{ font-size: 12px; font-family: Arial; }
  </style>
  <script type="text/javascript" src="script.js"></script>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
 <b>Successful Response (should be blank):</b>
<a href="#" onclick="check();">click me</a>
<div id="success"></div>
<div id="b"></div>


</body>
</html>

测试.php

<div id='target'>
 I am from test page. <a href="#" onClick="loaddata()">Click Here</a>
</div>

关于javascript - 是否可以在 div 中打开包含外部 javascript 和 css 的页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29360562/

相关文章:

javascript - 无法加载 bool 玛日历扩展

php - 模型更新时的 Laravel 必填字段

javascript - $.support.placeholder 在 jQuery 中意味着什么?

javascript - PHP 和 JavaScript 结合在一起

php - Slim Framework 的 HTTP 缓存不会过期

html - 在不使用 Html5 Canvas 的情况下更改部分区域的图像颜色

javascript - 将 url 从 html 传递给 javascript

javascript - 在计算的 Vue.js 中使用 props

javascript - 如何使用 Mootools 支持 IE 8-9 中的 'placeholder' 属性?

javascript - 当 prop 对象修改时,connect 不会改变子组件的 props