我想在<input>
中添加一个单词并更改输出。例如,
输入= Peter
输出= From Peter Parker
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;
这是所需的输出:
答案 0 :(得分:0)
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;