我试图通过ajax实时回显用户的输入来更新页面。但是,当用户键入某个内容并点击“发送”时,没有任何回应。但是,当我通过html将输入预设为随机单词并单击“发送”时,会显示该单词。为什么是这个,以及如何在html中手动更新输入值?更新用户输入的输入值
HTML
<input type="text" id="userName" name="typeit" value=""/>
<!-- Input containing preset value -->
<input type="text" id="userName" name="typeit" value="cindy"/>
<input type="button" id="text_value" value="send"/>
JQuery的
// I used this to check if the actual input was being updated
$('#text_value').click(function() {
var text_value = $("#userName").val();
if(text_value=='') {
alert("Please enter a title first");
}else{
alert(text_value);
}
});
? – jmore009
ajax在哪里? – adeneo
为什么你有两个具有相同ID和名称的输入? ID应该是唯一的。 – Ozan