我正在尝试实现这样的功能
- 如果我按,
non2
然后打印text2
textarea2
- 如果我然后按,
pos2
然后打印text2
。textarea1
这里我想要的是当我按下pos2
then 时将被打印text2
在textarea1
并且text2
intextarea2
将被删除。相反,如果我pos2
先击中non2
然后再击中,则仅text2
在textarea2
.
我正在考虑使用 if-else 语句来查看是否单击了 POS 或 NON 之一。这就是我最终的结果:
<?php
for ($j = 1; $j <= 3; $j++) {
echo '
<div id="part'. $j .'" >
<div id="teks'.$j.'">TEXT 2 </div>
<input type="radio" id="pos'. $j .'" name="teks'.$j.'" value="POS" onclick="addPOS(this.previousElementSibling.innerHTML);">POS2</input>
<input type="radio" id="non'. $j .'" name="teks'.$j.'" value="NON" onclick="addNON(this.previousElementSibling.previousElementSibling.innerHTML);">NON2</input>
<input type="radio" id="neg'. $j .'" name="teks'.$j.'" value="NEG" checked="checked" onclick="delPOS(document.getElementById(\'teks'.$j.'\').innerHTML); delNON(document.getElementById(\'teks'.$j.'\').innerHTML);">NEG2</input>
</div>
';
}
?>
<script type="text/javascript">
function delPOS(elem)
{
var txt = document.getElementById("posbox").value;
if (txt.length>elem.length){
document.getElementById("posbox").value = txt.substr(0,txt.length-elem.length-1);
}else{
document.getElementById("posbox").value="";
}
}
function delNON(elem)
{
var txt = document.getElementById("nonbox").value;
if (txt.length>elem.length){
document.getElementById("nonbox").value = txt.substr(0,txt.length-elem.length-1);
}else{
document.getElementById("nonbox").value="";
}
}
function delNEG(elem)
{
var txt = document.getElementById("negbox").value;
if (txt.length>elem.length){
document.getElementById("negbox").value = txt.substr(0,txt.length-elem.length-1);
}else{
document.getElementById("negbox").value="";
}
}
function addPOS(elem)
{
document.getElementById("posbox").value+=elem;
}
function addNON(elem)
{
document.getElementById("nonbox").value+=elem;
}
function addNEG(elem)
{
document.getElementById("negbox").value+=elem;
}
</script>
<div id="box" >
<textarea style="width:420px" name="posbox" id="posbox" rows="4" cols="70"></textarea>
<textarea style="width:420px" name="nonbox" id="nonbox" rows="4" cols="70"></textarea>
<textarea style="width:420px" name="negbox" id="negbox" rows="4" cols="70"></textarea>
</div>
但是,这不起作用。我做错了什么,我该如何解决?