0

I have a form button and I want 2 lines of text. In the form I have this

value='".$row['item'].'
$'.$row['price']."'

and I get

Hot Dog
$1.00

I want to update this in JavaScript and tried this

sBtn = itm + "
$" + prc;
document.getElementById(conbtn).value = sBtn;

and

sBtn = itm + "<br>$" + prc;
document.getElementById(conbtn).value = sBtn;

without success. The first gives

Hot Dog&#10;$1.00

and the second

Hot Dog<br>$1.00

Any idea how to write 2 lines from JS?

4

2 回答 2

1

我知道了。用过的

sBtn = itm + "\r\n$" + prc;
于 2012-12-31T02:50:20.033 回答
1

如果您有表单输入按钮,请在value属性中使用转义换行符。

document.getElementById(conbtn).value = "Test 1\nTest 2";

如果您有按钮标记元素,请在innerHTML属性中使用中断元素。

document.getElementById(conbtn).innerHTML = "Test 1<br/>Test 2";
于 2012-12-31T02:52:18.963 回答