我写了这段代码来替换div中的元素:"更改"使用文本框中给出的输入:" use10"当按钮:"插入"点击。但是当我点击什么都没有 正在发生请求帮助。这是我的代码:
<div id="change">
<?php
echo $r9['fname'];
echo " ";
echo $r9['lname'];
echo " ";
?>
</div>
<div id="dialog" title="Change Details">
<form method="POST" name="changename">
<input type="text" id="use10" name="use10" placeholder="First Name">
<input type="text" id="use20" name="use20" placeholder="Last Name">
<button type="button" type="submit" name="insert" id="insert" class="btn btn-success">Change</button>
<script>
document.getElementById("insert").onclick=function(){
var fn=getElememtById("use10").value;
document.getElementById("change").innerHTML=fn;}
</script>
</form>
</div>
答案 0 :(得分:0)
试试这个:
Jsfiddle:https://jsfiddle.net/74Lmwcmt/
$( document ).ready(function() {
document.getElementById("insert").onclick=function(){
var fn=document.getElementById("use10").value; // you forget to write "document." over here
document.getElementById("change").innerHTML=fn; // give id of div
}
});
OR
window.onload = function() {
document.getElementById("insert").onclick=function(){
var fn=document.getElementById("use10").value; // you forget to write "document." over here
document.getElementById("change").innerHTML=fn; // give id of div
}
};
答案 1 :(得分:0)
我刚刚使用了你的代码并稍微改了一下。看看这是否是你想要的。
<div id="change" title="Change Details">
<p> <form method="POST" name="changename"><input type="text" id="use10"
name="use10"
placeholder="First Name"> </p>
<p> <input type="text" id="use20" name="use20"
placeholder="Last Name"> </p>
<button type="button" type="submit" name="insert" id="insert" class="btn
btn-success">Change</button><script>
document.getElementById("insert").onclick=function(){
var fn=document.getElementById("use10").value;
document.getElementById("change").innerHTML=fn;}</script>
</form>
</div>