[英]PHP: How to add a CSS text-align property to an already present inline style attribute of an element using simple_html_dom parser?
[英]how to change text using style property in html, css
在此示例中,我有一個必須更改文本的按鈕。 現在,我知道可以使用onclick=document.getElementById('id').innerHTML="text"
但是我正在制作一個函數,使
**onclick = myFunc()**
<script>
function myFunc()
var x = document.getElementById('id');
x.style.property = 'text';
</script>
所以我的問題是,是否可以使用任何可以更改文本的屬性
不可以。“樣式”屬性用於樣式設置。 除了一些非常具體的例外,它們僅用於更改內容的外觀。 不更改內容本身。
innerHTML還有其他替代方法。 innerHTML用於將HTML內容添加到元素。
一種替代方法是textContent
。 將純文本添加到元素。
var x = document.getElementById('foo'); x.textContent = 'text';
<button id="foo">Hello World</button>
您可以使用設置文本:
<script>
function myFunc(){
var x = document.getElementById('btntext');
x.style.color = "green";
x.style.fontSize = "large";
x.value = "This is new TExt";
}
</script>
<body>
<input type="text" id="btntext" value="This test"/>
<button onClick="myFunc()" name="send">change color</button>
</body>
function changeText(id) { id.innerHTML = "Text has been changed!"; }
<h1 onclick="changeText(this)">Click on this text!</h1>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.