我有一个textarea和3个按钮,我需要将文本与这3个按钮对齐:左,中,右
<button type="button" onclick="myFunction()">LEFT</button>
<script>
function myFunction() {
document.getElementById("myP").style.textAlign = "left";
}
</script>
<button type="button" onclick="myFunction()">CENTER</button>
<script>
function myFunction() {
document.getElementById("myP").style.textAlign = "center";
}
</script>
<button type="button" onclick="myFunction()">RIGHT</button>
<script>
function myFunction() {
document.getElementById("myP").style.textAlign = "right";
}
</script>
<textarea name="textarea" id="myP" rows="10" cols="40"></textarea>
</div>
答案 0 :(得分:1)
function myFunction(align) {
document.getElementById("myP").style.textAlign = align;
}
<button type="button" onclick="myFunction('left')">LEFT</button>
<button type="button" onclick="myFunction('center')">CENTER</button>
<button type="button" onclick="myFunction('right')">RIGHT</button>
</script>
<textarea name="textarea" id="myP" rows="10" cols="40"></textarea>
</div>