我想在点击按钮时将id="insertValue"
的值转移到函数X
中的变量insert()
...
<input id="insertValue" type="text" />
<input type="button" value="Insert" onclick="insert('x')" />
答案 0 :(得分:1)
insert(document.getElementById('insertValue').value)
应该这样做。
但你的问题与ajax无关......
答案 1 :(得分:1)
试试这个。
JS:
function insert(e){
myValue = document.getElementById('insertValue').value;
// myValue is now set to the contents of the text field 'insertValue'
// let's check it...
alert(myValue);
}
HTML:
<input id="insertValue" type="text" />
<input type="button" value="Insert" onclick="insert(this)" />
我不明白您是否还想将按钮的值设置为文本字段的内容。如果你想(并且没有理由你需要),只需在JS函数中添加它。
e.value = myValue;