如何改变div的价值 [英] how can change value of a div

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

问题描述

"<div id="diva">this is div a</div>"
"<div id="divb"> this is div b</div>"

现在如何更改 div 通过按钮单击动态。这里还提到所有文本都来自数据库。当我点击按钮然后它检测到 div id并用欲望文本替换文本。

now how can I change the text of div dynamically by button click. here also mention that all text come from a database. when I click the button then it detects the div id and replace the text with desire text.

所有代码将在PHP中。

All code will be in PHP.

推荐答案

这将在页面加载后起作用:

This will work once the page is being loaded:

document.getElementById('diva').innerHTML = 
  <?php echo functionThatReturnsSomeValue(); ?>;

动态地,你需要在输出值的PHP文件上进行AJAX调用。如果使用jQuery之类的JS框架,而不是实现AJAX调用,那么你会更好。你自己

Dynamically, you would need to do an AJAX call on the PHP file which outputs a value. You'd be better off if you used a JS framework such as jQuery, rather than implementing the AJAX call yourself.

这篇关于如何改变div的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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