jQuery获取输入类型为text的文本 [英] jquery getting the text writed in the input type text
问题描述
我正在寻找解决方案,但我还不走运.
I'm looking for a solution but I haven't got lucky.
如果我有这个:
<input type="text" name="x" id="x" value="123"/>
我在jquery中有这个.
and I have this in jquery.
$('#x').val()
它返回我-> 123正确.
it returns me -> 123 thats correct.
但是,如果我想首先使用123作为默认值来编辑该字段,然后我将其重写为321,并在Jquery中执行相同的命令,则我仍然使用123而不是321.
But if I want to edit that field firstly with 123 as the default value and I re-write to 321 and I make the same command in Jquery, im still having 123 instead of 321.
所以问题是,如何获得在文本输入中输入的内容.
So the question is how can I get what I have written in the type text input.
谢谢大家!
这是我的html代码:
Here my html code:
<input type="text" name="hotel_name" id="edit_hotel_name" class="edit_hotel_name w100p" value="<?php echo $hotel['hotel_name'];?>"/>
这是我的jquery对话处理器:
Here my jquery dialog processor:
$("#dialog_hotel_content_edit_" + id_hotel).removeClass("hidden").dialog({
dialogClass: "no-close",
title: "Editar Hotel",
height: "auto",
width: "auto",
open: function(){
get_corporations();
get_zones($("#edit_state_id").val());
},
buttons: [{
text: "Editar",
click: function() {
hotel_name = $(".edit_hotel_name").val()
alert(hotel_name);
$(this).dialog( "close" );
}
}
]
});
这里的任务是通过对话框编辑一些信息,因此该信息来自value属性,然后当我单击"Editar"按钮时,它将获取以表格形式编写的信息.
The task here is to edit some information through a dialog, so the information comes by the value attribute and then when I click the "Editar" button it gets the information written in the form.
推荐答案
在jQuery中轻松自如.只需使用.on('input'
函数
Easy peasy in jQuery. Just use the .on('input'
function
$('#x').on('input', function() {
//do whatever you need to in here
});
有关如何使用它的示例: JSFiddle
example on how to use this: JSFiddle
这篇关于jQuery获取输入类型为text的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!