用文本填充div [英] Fill div with text

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

问题描述

我有一个 div

<div id="shoppingBasket">
</div>

使用Javascript或Jquery,我会如何填写默认文本:

Using Javascript or Jquery how would I fill this with the default text:

您的购物篮中没有商品。

我的意思是默认文字是我想在点击产品后改变文字。所以也许默认的文本在变量中,然后通过JavaScript或Jquery包含在div中,这将允许操纵变量。

What I mean by default text is I would want to change the text after they clicked a product. so maybe the default text in a variable and then included in the div via JavaScript or Jquery, which would allow the variable to be manipulated.

推荐答案

您可以使用jQuery text()或javascript innerText

You can do it using jQuery text() or javascript innerText

使用jQuery,使用jQuery text()

With jquery, using jQuery text()

$('#shoppingBasket').text("you have no products in your shopping basket.");

使用Javascript,使用 innerText

With Javascript, using innerText

document.getElementById("shoppingBasket").innerText = "you have no products in your shopping basket.";

这篇关于用文本填充div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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