Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.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 如何从test.html更改索引元素_Php_Javascript_Jquery_Html_Ajax - Fatal编程技术网

Php 如何从test.html更改索引元素

Php 如何从test.html更改索引元素,php,javascript,jquery,html,ajax,Php,Javascript,Jquery,Html,Ajax,您好,我需要在test.html上创建一个表单,单击该表单可以使用输入元素更改索引元素(标题、图像、描述(文本)和a href属性)。你能帮我吗 index.html <html> <body> <p id="pal">This is a paragraph.</p> <p>This is another paragraph.</p> <button id="ch">Replace the first p ele

您好,我需要在test.html上创建一个表单,单击该表单可以使用输入元素更改索引元素(标题、图像、描述(文本)和a href属性)。你能帮我吗

index.html

<html>
<body>
<p id="pal">This is a paragraph.</p>
<p>This is another paragraph.</p>
<button id="ch">Replace the first p element with new text</button>

</body>
</html>

这是一个段落

这是另一段

用新文本替换第一个p元素
test.html

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("#ch").click(function(){
    $("#pal").replaceWith(#in1);
  });
});
</script>
</head>
<body>
<input id="in1" type="text"></input>
<input id="in2" type="text"></input>
</body>
</html>

$(文档).ready(函数(){
$(“#ch”)。单击(函数(){
$(“#pal”)。替换为(#in1);
});
});

好的,如果我理解得很好,您有一个输入标签,用户将在其中写入内容,当他单击按钮时,内容将转到另一个地方

在他写的地方输入:

<input type="text" id="user_text">

如果您想查看结果,这里是

您能帮助我们吗?你的密码在哪里?你能发布一个现场演示吗?我只有索引,我想让你们告诉我如何进行测试。htmlCheck在这里好的,谢谢;)抱歉,没有澄清问题是
$(“#pal”)。替换为(#in1)。您可能需要类似于
var content=$(“#in1”).html()的内容$(“pal”)。替换为(内容)哇,好极了,但是你能把TEST.HTML替换成INDEX.HTML吗?明白了吗?JQuery只会更改当前加载的页面。是否要“提交”表单并加载包含此新内容的index.html?是吗?是的,这就是我想说的,但是我英语说得不好,所以我不能表达自己,很抱歉我不清楚我的意思。如果这是您想要的,JQuery不是最好的解决方案。您应该使用PHP来实现这一点。表单应该有一个PHP文件作为操作,该文件读取表单并加载index.html(或者更确切地说是index.PHP),然后通过POST变量发送文本。然后,您将使用该数据构建页面。阅读更多:,无论如何,再次非常感谢,很抱歉,我没有足够的声望来评价你的答案是否有用:S我将阅读有关php的内容并尝试制作一些东西,再次感谢
<p id="pal">This is the target.</p>
<button id="ch">Replace the first p element with new text</button>
$(document).ready(function(){
  //on click
  $("#ch").click(function(){
    //get content from input (what user wrote)
    var userContent = $("#user_text").val();
    //put it inside the desired div
    $("#pal").html(userContent);
    //clean what user wrote
    $("#user_text").val('');
  });
});