如何通过追加PHP和AJAX后一个divPHP、AJAX、div

由网友(你是我无法触摸的温柔)分享简介:美好的一天。我试图让使用PHP的在线测试应用程序。我们的想法是,该形式将增加一个文本字段的问题,并在它下面的其他四个文本字段的答案每一个无线电按钮,确定哪一个是正确的。然后下面的表格是附加了一个新问题按钮,会叫一个ajax后的功能。现在的问题是,而不是附加到目标分区,PHP的code替换DIV本身的内容。有没有办法让P...

美好的一天。我试图让使用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>');
阅读全文

相关推荐

最新文章