Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.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 将按钮值发布到不同的html文件_Javascript_Jquery_Html - Fatal编程技术网

Javascript 将按钮值发布到不同的html文件

Javascript 将按钮值发布到不同的html文件,javascript,jquery,html,Javascript,Jquery,Html,基本上,我有两个按钮,当它们被点击时更新我的datatable <html> <head> <script type="TEXT/JAVASCRIPT"> function seta() { document.let.out.value = "s" } </script> </head> <bo

基本上,我有两个按钮,当它们被点击时更新我的
datatable

<html>
    <head>
        <script type="TEXT/JAVASCRIPT">
            function seta() {
                document.let.out.value = "s"
            }

        </script>
    </head>
    <body>
        <form action="#" name="let">

            <input type=BUTTON value="s" onclick="seta()">


            <table id="dataTable" width="350px" border="1">
                <td width="177" align="left"><strong>eggs</strong></td>
                </TR>

                <td><output type=TEXT name="out" size=60 enabled>  </td>
                </TR>

                <td><output type=TEXT name="poo" size=60 disabled>  </td>
            </table>
    </body>
</html>
这将更新不同html文件中的
数据表,例如
page2

<html>

    <head>
<script type="text/javascript">
      src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js">
          }

            function seta() {
                document.let.out.value = "s"

            }



        </script>

    </head>




    <body>
        <table id="dataTable" width="350px" border="1">
            <td width="177" align="left"><strong>eggs</strong></td>
            </TR>

            <td><output type=TEXT name="out" size=60 disabled></td>
            </TR>

        </table>
    </body>
</html>

src=”https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js">
}
函数seta(){
document.let.out.value=“s”
}
鸡蛋

我完全不知道这一点,因此非常感谢您提供的任何帮助,谢谢:)

您可以使用AJAX或涉及活动服务器的类似技术来实现这一点。其中一个页面会将一些信息推送到服务器,另一个页面会从服务器检索信息,更新其值

如果不使用服务器端技术(如您所说,如果您是一个“完全的noob”,您可能会更习惯使用服务器端技术),您可以使用一个。创建一个包含两个iFrame的页面,一个包含按钮的页面,另一个包含按钮正在操作的任何内容

显示了一个快速搜索,告诉您如何从另一个iframe操作iframe的内容


我想补充一下,如果你真的需要这些文件是分开的,你应该考虑一下。如果您希望在浏览器中查看的一个页面在其仍在服务器上时更改另一个文件,那么您将无法仅使用Javascript,这可能是一个坏主意。但是,如果两个文件都是同时显示在同一浏览器中的同一布局的一部分,那么为什么它们需要分开?你不能将它们合并成一个包含整个布局的更大的HTML文件吗?

好的!所以我找到了一个关于cookies的非常有见地的入门教程,这让我度过了一个富有成效的夜晚,至少现在有了一些成果。。。这是我所拥有的

//this is to send the cookie "cooked"

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
cookie_name = "cooked";
var send;

function putCookie() {

if(document.cookie != document.cookie) 
{index = document.cookie.indexOf(cookie_name);}
else 
{ index = -1;}
if (index == -1)
{
send=document.it.itr.value;
document.cookie=cookie_name+"="+send+"; expires=Wednesday, 01-Jan-2020 05:00:00 GMT";}
}
</SCRIPT>

<FORM NAME="it">
Enter A Word: <INPUT TYPE="text" NAME="itr" size="20">
<INPUT TYPE="button" Value="send cookies!" 
onClick="putCookie()">
</FORM>

<body/>
</head>
<html/>


//this is to receive the cookie "cooked"

<html>
<head>

<SCRIPT LANGUAGE="JavaScript">

cookie_name = "cooked";
var received;

function getName() {
if(document.cookie)
{
index = document.cookie.indexOf(cookie_name);
if (index != -1)
{
namestart = (document.cookie.indexOf("=", index) + 1);
nameend = document.cookie.indexOf(";", index);
if (nameend == -1) {nameend = document.cookie.length;}
received = document.cookie.substring(namestart, nameend);
return received;
}
}
}

received=getName();
if (received == "cooked")
{received = "Nothing_Entered"}
</SCRIPT> 


<SCRIPT LANGUAGE="javascript">
document.write("<FORM>")
document.write("you wrote:") 
document.write("<INPUT TYPE=text SIZE=30 VALUE=" +received+ ">");
document.write("</FORM>")
</SCRIPT>
    </BODY>
    </head>
    </HTML>


which works great, although it obviously won't function on ios...
//这是为了发送cookie“cooked”
cookie_name=“熟食”;
var发送;
函数putCookie(){
if(document.cookie!=document.cookie)
{index=document.cookie.indexOf(cookie_name);}
其他的
{index=-1;}
如果(索引==-1)
{
发送=document.it.itr.value;
document.cookie=cookie\u name+“=”+send+“expires=2020年1月1日星期三05:00:00 GMT”}
}
输入一个单词:
//这是为了接收“煮熟”的饼干
cookie_name=“熟食”;
收到的风险值;
函数getName(){
if(document.cookie)
{
index=document.cookie.indexOf(cookie\u名称);
如果(索引!=-1)
{
namestart=(document.cookie.indexOf(“=”,index)+1);
nameend=document.cookie.indexOf(“;”,index);
如果(nameend==-1){nameend=document.cookie.length;}
received=document.cookie.substring(namestart,nameend);
收到的报税表;
}
}
}
received=getName();
如果(收到=“煮熟”)
{received=“Nothing_Entered”}
文件。写(“”)
document.write(“你写的:”)
文件。填写(“”);
文件。写(“”)
虽然它显然不会在ios上运行,但它工作得很好。。。

您的html有点凌乱。F.e.你要关门了,但没有……你有什么问题?如何捕获值或如何发送它们?或者两者都有?你想用js做所有事情吗?因为我建议在php中这样做,因为js是在clientside上执行的。ye很抱歉,我昨天才开始画这个,我对js只有一个真正的基本知识,对php一无所知。ye当我点击“page1”上的一个按钮时,我想更新“page2”上的表,所以ye从“page1”发送按钮点击将在“第2页”接收表格,表格将。。。我读过关于Ajax的书,但我只能得到一个静态值来加载,我读过Ajax,但到目前为止,我只能设法加载一个静态值,我想要的是表格为空,除非在不同的页面上单击一个按钮。。。iframe这个东西对我也不起作用,因为我不想让任何人看到“page2”上表格的内容,直到我将他们重定向到它。。。我想我希望按钮的功能类似于“添加到购物车”按钮,并且表格位于另一个页面上,功能类似于“购物车”,显示单击了哪些按钮。。。根据点击的内容,该表将只包含指向可下载内容的链接……通常,购物车功能是通过让网页将一些数据发布到服务器并由服务器将其保存在数据库或用户会话中来实现的。服务器在处理完帖子后,会回复一个使用存储信息填充的网页。是的,我可以理解它是如何工作的,对吗?问题是,从技术上讲,我对php一无所知,我认为可能有一种非常简单的方法可以用js实现同样的功能,也许……你可能想看看如何设置和读取Javascript中的cookie。如本文所述:
//this is to send the cookie "cooked"

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
cookie_name = "cooked";
var send;

function putCookie() {

if(document.cookie != document.cookie) 
{index = document.cookie.indexOf(cookie_name);}
else 
{ index = -1;}
if (index == -1)
{
send=document.it.itr.value;
document.cookie=cookie_name+"="+send+"; expires=Wednesday, 01-Jan-2020 05:00:00 GMT";}
}
</SCRIPT>

<FORM NAME="it">
Enter A Word: <INPUT TYPE="text" NAME="itr" size="20">
<INPUT TYPE="button" Value="send cookies!" 
onClick="putCookie()">
</FORM>

<body/>
</head>
<html/>


//this is to receive the cookie "cooked"

<html>
<head>

<SCRIPT LANGUAGE="JavaScript">

cookie_name = "cooked";
var received;

function getName() {
if(document.cookie)
{
index = document.cookie.indexOf(cookie_name);
if (index != -1)
{
namestart = (document.cookie.indexOf("=", index) + 1);
nameend = document.cookie.indexOf(";", index);
if (nameend == -1) {nameend = document.cookie.length;}
received = document.cookie.substring(namestart, nameend);
return received;
}
}
}

received=getName();
if (received == "cooked")
{received = "Nothing_Entered"}
</SCRIPT> 


<SCRIPT LANGUAGE="javascript">
document.write("<FORM>")
document.write("you wrote:") 
document.write("<INPUT TYPE=text SIZE=30 VALUE=" +received+ ">");
document.write("</FORM>")
</SCRIPT>
    </BODY>
    </head>
    </HTML>


which works great, although it obviously won't function on ios...