Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.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 使用onClick函数获取ID,并将其填充到不同的html中_Javascript_Html - Fatal编程技术网

Javascript 使用onClick函数获取ID,并将其填充到不同的html中

Javascript 使用onClick函数获取ID,并将其填充到不同的html中,javascript,html,Javascript,Html,我有一个HTML页面,加载一个表和一个DHTMLX甘特图。下面的javascript函数可以工作,但现在我想从不同的html加载甘特图,并通过iframe显示它 如何从主页.html表中获取内容\u id,并将其填充到调度程序.html甘特图中 每个人都乐于助人 main_page.html <table id="project-content-datatable"> <tbody> <tr> <td cl

我有一个HTML页面,加载一个表和一个DHTMLX甘特图。下面的javascript函数可以工作,但现在我想从不同的html加载甘特图,并通过iframe显示它

如何从
主页.html
表中获取
内容\u id
,并将其填充到
调度程序.html
甘特图中

每个人都乐于助人

main_page.html

<table id="project-content-datatable">
    <tbody>
        <tr>
            <td class="project_content_id">1</td>
            <td class="project_content_id">2</td>
            <td class="project_content_id">3</td>      
        </tr>
    </tbody>
</table>

<div class="col-md-12" style="padding: 3px; margin: 0px;">
     <iframe src="/dashboard/projects/scheduler.html" height="330"; width="99%" style="border:2px  solid blue; border-radius: 5px;"></iframe>
</div>

一种简单的方法是动态创建传递给iframe的url:

<div class="col-md-12" style="padding: 3px; margin: 0px;">
    <iframe id="iframe" height="330"; width="99%" style="border:2px  solid blue; border-radius: 5px;"></iframe>
</div>

现在,在iframe中,您可以从
窗口.hash
获取内容id。在这种特定情况下,可以使用子字符串轻松地提取id,但对于更完整的方法,您可以使用一个函数从url中提取查询参数,如下所述:

一种简单的方法是调用动态创建传递给iframe的url:

<div class="col-md-12" style="padding: 3px; margin: 0px;">
    <iframe id="iframe" height="330"; width="99%" style="border:2px  solid blue; border-radius: 5px;"></iframe>
</div>
现在,在iframe中,您可以从
窗口.hash
获取内容id。在这种特定情况下,可以使用子字符串轻松地提取id,但对于更完整的方法,可以使用从url提取查询参数的函数,如下所述:

<div class="col-md-12" style="padding: 3px; margin: 0px;">
    <iframe id="iframe" height="330"; width="99%" style="border:2px  solid blue; border-radius: 5px;"></iframe>
</div>
var url = "/dashboard/projects/scheduler.html?content_id=" + content_id;
document.getElementById('iframe').src = url;