【发布时间】:2020-08-05 09:29:48
【问题描述】:
我正在做一个二进制数的计算器。我使用文本输入字段输入二进制数和运算符,在其中我使用虚拟按钮输入值,我希望当输入字段溢出时它应该看起来像 [...10100101010] 因此我使用了 CSS {direction : rtl; text-overflow: ellipsis;} 但我遇到了一个问题,即当我通过单击使用与其他按钮相同的功能的按钮输入任何运算符时,运算符看起来像 [+10001] 而不是像 [10001+] . 帮我解决上述问题。我的代码如下。
<html>
<title>Binary Calculator</title>
<head>
</head>
<body>
<input id="input" style="direction:rtl; text-overflow:ellipsis;" type="text" >
<br>
<br>
<input onclick="enter('0')" value="0" type="button">
<input onclick="enter('1')" value="1" type="button">
<input onclick="enter('+')" value="+" type="button">
<input onclick="convert()" value="Convert" type="button">
<script>
function enter(n_val){
document.getElementById("input").value += n_val
}
</script>
</body>
</html>
【问题讨论】:
标签: javascript html css textfield input-field