Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.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
Javascript 有载函数_Javascript_Jquery_Html - Fatal编程技术网

Javascript 有载函数

Javascript 有载函数,javascript,jquery,html,Javascript,Jquery,Html,请看下面的脚本: <script type="text/javascript"> $(document).ready(function() { $('#content').load('divelencoarticoli.html'); }); </script> $(文档).ready(函数(){ $('#content').load('divelencoartoli.html'); }); 在页面master.html中加载名为develencoartic

请看下面的脚本:

<script type="text/javascript">
$(document).ready(function() {
    $('#content').load('divelencoarticoli.html');
});
</script>

$(文档).ready(函数(){
$('#content').load('divelencoartoli.html');
});
在页面master.html中加载名为develencoarticoli.html的子页面,位于该div的正文中:

<div style="width: 100%" id="content">Initial content in test.html</div>
test.html中的初始内容 我的问题是:是否可能有一个脚本在DIV中加载DIV中指定的页面内容?我不想从脚本中调用页面,但脚本知道该页面是否包含在div内容中。 我的目标是,在我网站的所有页面中使用一个通用脚本,我可以在主体中加载DIV内容调用的不同页面

对不起,我的英语和我的问题,但我不是开发人员

提前谢谢



多亏了ken.dunnington和epascarello,问题解决了。

您可以通过ajax调用获取html。下面是使用jquery的代码

<script type="text/javascript">
$(document).ready(function() {

$.get( "ajax/divelencoarticoli.html", function( data ) {
  $( "#content" ).html( data );
  alert( "Load was performed." );
});

});
</script>

$(文档).ready(函数(){
$.get(“ajax/divelencoartoli.html”,函数(数据){
$(“#content”).html(数据);
警报(“已执行加载”);
});
});

您要使用的是一个带有要加载的url的数据属性

<div style="width: 100%" id="content" data-load-url="divelencoarticoli.html">Initial content in test.html</div>

如果我理解正确,您希望能够将外部内容加载到
#content
div中,而无需在Javascript中明确说明要使用哪个URL,并且能够在多个页面上使用相同的代码。如果是这样,我建议使用
data-*
变量,如下所示:

<div style="width: 100%" id="content" data-content-url="divelencoarticoli.html">Initial content in test.html</div>
<script type="text/javascript">
    $(function() {
        var contentDiv = $("#content");
        var url = contentDiv.data("content-url");
        contentDiv.load(url);
    });
</script>
test.html中的初始内容 $(函数(){ var contentDiv=$(“#content”); var url=contentDiv.data(“内容url”); contentDiv.load(url); }); jQuery在第一次访问元素时自动将
数据-*
属性转换为可通过
.data()
方法访问的值。因此,您可以在每个页面上包含上面的脚本块,只需根据需要更改
#content
div中的数据url。

根据我的理解,您希望通过PASS url动态包含页面,因此您可以在以下方式中执行此操作:
    According to my understanding u want to include the page dynamically by pasing the URL so you do this in this mannner :

<script type="text/javascript">
    function do_the_click(url)
        {
        alert(brl);
        var request  =   $.ajax({
                                 async: false,
                                 url: url, 
                                 contentType: "text/html",
                                 type : "GET",
                                 dataType : "html",                

                    });


                        request.done(function( msg ) {
                          document.getElementById('pass here the ID of div in which the page is included').innerHTML = msg;
                        });

                        request.fail(function( jqXHR, textStatus ) {
                          alert( "Request failed: " + textStatus );
                        });

        }
    </script>

and the HTML boby code should be 
<div id="tagmenu">

            <a href="#" class="button" id="activity" onclick="do_the_click('category/ABB.html');"/>ABB</a>
            <a href="#" class="button" id="javacollections" onclick="do_the_click('category/ABC.html');"/>ABC</a>
    </div>
函数dou\u单击(url) { 警报(brl); var请求=$.ajax({ async:false, url:url, contentType:“文本/html”, 键入:“获取”, 数据类型:“html”, }); request.done(函数(msg){ document.getElementById('在此处传递包含页面的div的ID')。innerHTML=msg; }); 请求失败(函数(jqXHR,textStatus){ 警报(“请求失败:+textStatus”); }); } HTML boby代码应该是
如果可以,您介意重新键入您的问题吗?我几乎听不懂你在说什么。你是说你不想把url“divelencoartoli.html”硬编码到脚本中?或者你是说你只想加载“divelencoartoli.html”页面的一部分?你的问题没有得到回答,因为很难理解你在问什么..哎呀,epascarello比我快了。:)非常感谢,问题解决了。意大利的问候
    According to my understanding u want to include the page dynamically by pasing the URL so you do this in this mannner :

<script type="text/javascript">
    function do_the_click(url)
        {
        alert(brl);
        var request  =   $.ajax({
                                 async: false,
                                 url: url, 
                                 contentType: "text/html",
                                 type : "GET",
                                 dataType : "html",                

                    });


                        request.done(function( msg ) {
                          document.getElementById('pass here the ID of div in which the page is included').innerHTML = msg;
                        });

                        request.fail(function( jqXHR, textStatus ) {
                          alert( "Request failed: " + textStatus );
                        });

        }
    </script>

and the HTML boby code should be 
<div id="tagmenu">

            <a href="#" class="button" id="activity" onclick="do_the_click('category/ABB.html');"/>ABB</a>
            <a href="#" class="button" id="javacollections" onclick="do_the_click('category/ABC.html');"/>ABC</a>
    </div>