如何通过追加PHP和AJAX后一个div [英] How to append a div via PHP and AJAX Post

查看:123
本文介绍了如何通过追加PHP和AJAX后一个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天。我试图让使用PHP的在线测试应用程序。我们的想法是,该形式将增加一个文本字段的问题,并在它下面的其他四个文本字段的答案每一个无线电按钮,确定哪一个是正确的。然后下面的表格是附加了一个新问题按钮,会叫一个ajax后的功能。现在的问题是,而不是附加到目标分区,PHP的code替换DIV本身的内容。有没有办法让PHP能追加到div,而不是取代它的内容是什么?

Good day. I'm trying to make an online quiz application using php. The idea is that the form will add a text field for the question and four other text fields below it for the answers each with a radio button to determine which one is correct. Then below the form is an add a new question button which would call an ajax post function. The problem is instead of appending to the target div, the php code replaces the contents of the div itself. Is there a way for php to append to the div instead of replace its contents?

推荐答案

PHP是服务器端,它不能在浏览器中做任何事情,只提供内容。

PHP is server-side, it can't do anything in the browser, only deliver content.

要添加一个div,你在页面上使用JavaScript,如:

To add a div, you use Javascript in the page, e.g.

var el = document.getElementById('idoftarget');
el.innerHTML += '<div>new stuff</div>

......我想。我总是用jQuery的:

... I think. I always use jQuery:

$('#idoftarget').append('<div>new stuff</div>');

这篇关于如何通过追加PHP和AJAX后一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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