简体   繁体   English

在同一文本区域内显示多个函数值

[英]Display more than one function value inside the same textarea

<script type="text/javascript">function TotalPrice( arg1 ) parent.document.getElementById location.search.substring(1)).value = arg1;}</script>

<script type="text/javascript"> function Misure( arg2 ){parent.document.getElementById(location.search.substring(1)).value = arg2;}</script>

I have two functions that each of them should send a value to the same textarea. 我有两个函数,它们每个都应将值发送到相同的textarea。 The script does not take me both function values but only the last one; 该脚本不带我两个函数值,而带我只有最后一个。 how can I display inside the two textarea both the values? 如何在两个文本区域中同时显示两个值? thanks 谢谢

If your functions are setting the '.value' property of the same textarea, then the whole value will be overwritten each time. 如果您的函数设置了相同文本区域的'.value'属性,则每次都将覆盖整个值。

If you want to add something on to the current value of the textarea you can use the += operator, which will add the value to the current value 如果要在textarea的当前值上添加一些内容,可以使用+=运算符,这会将值添加到当前值

function TotalPrice( arg1 ) {
     parent.document.getElementById(location.search.substring(1)).value += arg1;
}

function Misure( arg2 ){
     parent.document.getElementById(location.search.substring(1)).value += arg2;
}

Your second call is overwriting the value set by the first call. 您的第二个电话正在覆盖第一个电话设置的值。 If you need the args to be concatenated, you can replace node.value = arg by node.value += arg . 如果需要将args串联,则可以将node.value = arg替换为node.value += arg

However, in this case, each subsequent calls argument will be added at the end of the value and you may need to clear it at some point. 但是,在这种情况下,每个后续调用参数都将添加到值的末尾,您可能需要在某个时候清除它。

 var target = document.getElementById("target"); function totalPrice(arg1){ target.value += arg1; } function misure(arg2){ target.value += arg2; } function reset(){ target.value = ""; } 
 <input id="target" /> <button onclick="totalPrice('total');">total</button> <button onclick="misure('misure');">misure</button> <button onclick="reset();">clear</button> 

If I understand correctly looks like your just replacing the initial value after your first function (if you call them sequentially). 如果我理解正确,则看起来您只是在第一个函数后替换了初始值(如果您依次调用它们)。 Try concatenating the textarea values in the second function. 尝试在第二个函数中串联textarea值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM