在jquery php中打开一个url

X10*_*0nD 1 php jquery

当我点击"点击这里"然后必须在里面打开一个页面

<script....>
$('yahoo').html('<a href=desc.php>');
</script>

<div id='yahoo'></div>
<div id='clickhere'>Click here</div>
Run Code Online (Sandbox Code Playgroud)

谢谢戴夫

Tat*_*nen 7

我想你正在寻找AJAX来为你获取页面.像这样的东西可能会起作用:

<script type="text/javascript">
    $(function() {
        $('#clickhere').click(function() {
            $('#yahoo').load('desc.php');
        });
    });
</script>

<div id='yahoo'></div>
<div id='clickhere'>Click here</div>
Run Code Online (Sandbox Code Playgroud)

首先,您需要将脚本包装$(function() { ... })在页面加载中执行代码.这相当于$(document).ready(function() { ... }).

接下来,您必须将click事件绑定到#clickhere元素,以便在用户单击它时实际执行某些操作.

当用户单击#clickherediv时,load()将从您调用它的元素中获取给定URL的内容.所以,这个片段意味着当#clickhere单击div 时,desc.php会在#yahoodiv中加载.