Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何防止在点击超链接后重新加载页面,但重定向到该页面并编写出必要的代码?_Php_Jquery_Html_Anchor_Page Refresh - Fatal编程技术网

Php 如何防止在点击超链接后重新加载页面,但重定向到该页面并编写出必要的代码?

Php 如何防止在点击超链接后重新加载页面,但重定向到该页面并编写出必要的代码?,php,jquery,html,anchor,page-refresh,Php,Jquery,Html,Anchor,Page Refresh,我的问题听起来可能令人困惑,但实际上并非如此。让我把事情告诉你。该场景是我有以下HTML代码: /*This is the hyperlink I've given for example here. Many such hyperlinks may present on a webpage representing different question ids' */ <a delhref="http://localhost/eprime/entprm/web/control/modul

我的问题听起来可能令人困惑,但实际上并非如此。让我把事情告诉你。该场景是我有以下HTML代码:

/*This is the hyperlink I've given for example here. Many such hyperlinks may present on a webpage representing different question ids' */
<a delhref="http://localhost/eprime/entprm/web/control/modules/questions/manage_question_issue.php?op=fixed&question_id=21679" title="Fixed" href="#fixedPopContent" class="fixed" data-q_id="21679" id="fix_21679">Fixed</a>

/*Following is the HTML code for jQuery Colorbox pop-up. This code has kept hidden initially.*/
<div class="hidden">
  <div id="fixedPopContent" class="c-popup">
    <h2 class="c-popup-header">Question Issue Fix</h2>
    <div class="c-content">         
      <h3>Is question reported issue fixed?</h3>
      <a href="#"class="c-btn" id="fixedPop_url">Yes</a>
      <a href="#"class="c-btn">No</a> 
    </div>
  </div>
</div>
你可以用它来做。这是一个例子

HTML:

<a href="/delete/1">Delete</a>
<a href="/update/2">Update</a>


<div id="content"></div>
var History = window.History;
if (!History.enabled) {
    return false;
}

History.Adapter.bind(window, 'statechange', function() {
    var State = History.getState();

    $('#content').load(State.url);
});

$('body').on('click', 'a', function(e) {

    var urlPath = $(this).attr('href');
    var Title = $(this).text();
    History.pushState(null, Title, urlPath);
    return false;
});
您可以在这里看到代码:

您可以在这里看到演示:


注意:无法找到示例中的URL。您需要根据需要进行更新。这很简单,在href中加载内容而不刷新页面。

因此,您需要在url处加载页面,而不是导航到页面

你可以用

因此,在您的例子中,假设您的pop container div类是
.popup
,并且您要加载URL内容的div有一个id,即
#container

$(".popup a").on('click', function(e){
e.preventDefault();
var url = $(this).attr('delhref');

$("#container").load(url);

});
没什么要记住的

  • 这对于指向任何其他域的URL都不起作用。(同一原产地政策)
  • 应将使用此功能加载的任何内容(
    .load()
    )插入容器中,并执行所有输入脚本(如有)

  • 将e.preventDefault()添加为$('.fixed')中的第一行。单击(函数(e){您到底想做什么?这一点令人困惑…”页面正在重定向到href属性值,页面将重新加载。实际上,我想访问href属性中提到的页面,但页面不应重新加载或刷新。如何实现此目的?”@Bryan:我想从href属性中提到的页面执行代码,但该页面不应加载。我想阻止锚定标记的正常行为,我尝试了e.preventDefault(),但没有成功。怎么没有成功?您需要进行ajax调用以在不加载页面的情况下运行该页面。
    $(".popup a").on('click', function(e){
    e.preventDefault();
    var url = $(this).attr('delhref');
    
    $("#container").load(url);
    
    });