更改另一页上div的内容 [英] Change content of a div on another page

查看:66
本文介绍了更改另一页上div的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在第1页,我有一个 div 包含信息。

On page 1, I have a div containing information.

<div id='information'></div>

在第2页,我有表单使用 textarea 和一个按钮。

And on page 2, I have a form with a textarea and a button.

<form>
  <textarea id='new-info'></textarea>
  <input type='submit' id='submit-info' value='pass'/>
</form>

现在我想要的是当我点击提交按钮时,文本区域中输入的文字将是发布在 div #information 更改以前的内容。

我看过很多关于如何更改div内容的帖子,但那些与我的问题无关。

Now what I want is when I click the submit button, the text inputted in the text area will be posted in div#information changing its previous content.
I have seen many other post on how to change div content, but those were unrelated to my problem.

推荐答案

希望这会让你知道如何做到这一点:

Hope this will give you an idea of how you can do it:

HTML

<form>
  <textarea id='new-info'></textarea>
  <input type='submit' id='submit-info' value='pass'/>
</form>

JS

$("form").submit(function(e){

    e.preventDefault();

    $.post('save_data.php', { new_info:$("#new-info").val() }).done(function(data){
         // Do something if you want to show that form has been sent
    });


});

save_data.php

<?php

if (isset($_POST['new-info'])) {

    // Update value in DB

}


?>



Page 1



HTML

<div id='information'>
</div>

JS

setInterval(search_after_info, 1000);


function search_after_info() {

    $.get('get_data', function(data) {

        $("#information").html(data);

    });

}

这篇关于更改另一页上div的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆