我有一个输入,但想要一个不同的输出

时间:2018-04-10 10:28:00

标签: javascript html

我想在<input>中添加一个单词并更改输出。例如,

输入= Peter

输出= From Peter Parker

&#13;
&#13;
function impf1() {
  var first = document.getElementById("imp1").value;
  var out1 = "print(" + first + ")";
  return out1;
  console.log(out1);
  window.alert(out1);
  return false;
}
&#13;
<h5></h5>

<div class="hr">
  <hr />
</div>
<h3></h3>

<center><select>
<option value="python">Python</option>
</select></center>

<center>
  <button onclick="impf1()">GET CODE</button>
</center>
&#13;
&#13;
&#13;

这是所需的输出:

desired output

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
function impf1() {
  var first = document.getElementById("imp1").value;

  var out1 = "print(" + first + ")";
  document.getElementById("showdata").textContent="From "+first;
  return out1;
  console.log(out1);
  window.alert(out1);
  return false;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<h5></h5>

<div class="hr">
  <hr />
</div>
<h3></h3>

<center><select>
<option  id= "imp1" value="Peter Parker">Peter</option>
</select></center>

  <button onclick="impf1()">GET CODE</button>
</center>

<center>
  <div id="showdata"></div>
</center>
&#13;
&#13;
&#13;