单击按钮时如何在正文中显示用户输入

时间:2017-10-11 05:38:49

标签: javascript

我尝试在单独的div上显示用户输入,但只在单击按钮时显示。我想我已经设置了但是我不知道如何显示输入。谁可以帮助我如何做到这一点?



MyRadioButton tBtn = new MyRadioButton(new CGPoint(100, 300), "TEXT PHONE");
MyRadioButton eBtn = new MyRadioButton(new CGPoint(100, 375), "EMAIL");

this.Add(tBtn);
this.Add(eBtn);

tBtn.Tap += Btn_Tap;
eBtn.Tap += Btn_Tap;
// set the default selection
Btn_Tap(tBtn);

MyRadioButton PreviousButton;
private void Btn_Tap(MyRadioButton sender)
{
    if(PreviousButton != null)
    {
        //set previous to false
        PreviousButton.State = false;
    }
    //set current to true
    sender.State = true;
    //assign current to previous
    PreviousButton = sender;
}

<script>
    var callButt = document.getElementById("callButt");
    var userinput = document.getElementById("userinput");

    callButt.addEventListener("click", function(){
    console.log("Call has been set");

    userinput.style.display = "block";

</script>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

input value设置为div的innerHTML

&#13;
&#13;
var callButt = document.getElementById("callButt");
var userinput = document.getElementById("userinput");
callButt.addEventListener("click", function() {
      console.log("Call has been set");
      userinput.innerHTML = document.getElementById('callerIDInput').value
      })
&#13;
<input id="callerIDInput" type="text" value="">
<div id="userinput"> </div>

<button id='callButt'>CALL</button>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

使用DIV的innerHTML来设置值。

<强> HTML

<input id="callerIDInput" type="text" value="">
<div id="userinput"> </div>

<button id='callButt' onclick="Display()">CALL</button>

<强>的Javascript

function Display()
{
    var callButt = document.getElementById("callButt");
    var userinput = document.getElementById("userinput");
    var callerIDInput = document.getElementById("callerIDInput");
    console.log("Call has been set");
    userinput.style.display = "block";
    userinput.innerHTML = callerIDInput.value;
}