我要显示在ID结果数据 MyPlace酒店
跟随值 ID =号
如果
<输入类型=文本ID =数字NAME =数字值=5>
我要显示结果 ID =myplace5
如果
<输入类型=文本ID =数字NAME =数字值=7>
我要显示结果 ID =myplace7
我怎样才能做到这一点?
<脚本>
功能Check_register()
{
的setTimeout(函数(){
$就
(
{
网址:'test.php的',
键入:POST,
数据:$('#form_setup')序列化()。
缓存:假的,
成功:功能(数据){
$('输入')丙('只读',假); //此行将使所有输入成功后//
$('#MyPlace酒店)显示()。
$('#MyPlace酒店')的HTML(数据)。
}
}
)
},2000);
}
< / SCRIPT>
解决方案
由于'的 MyPlace酒店的'是一个input元素,则不能使用文本或HTML,你通常会。
相反,你需要做的是利用jQuerysVAL功能,如下所示:
$(#MyPlace酒店)VAL(html.data)。
html.data将包含从您的Web服务所获得的数据,并调用瓦尔将确保它添加到元素值属性。
i want to show result data in id myplace
follow value in id="number"
if
<input type="text" id="number" name="number" value="5">
i want to show result in id="myplace5"
if
<input type="text" id="number" name="number" value="7">
i want to show result in id="myplace7"
How can i do that ?
<script>
function Check_register()
{
setTimeout(function(){
$.ajax
(
{
url: 'test.php',
type: 'POST',
data: $('#form_setup').serialize(),
cache: false,
success: function (data) {
$('input').prop('readonly', false); // this line will enable all input after success //
$('#myplace').show();
$('#myplace').html(data);
}
}
)
}, 2000);
}
</script>
解决方案
Since 'Myplace' is an input element, you can't use 'text' or 'html' as you would normally.
Instead what you need to do is use jQuerys 'val' function, as follows:
$("#myplace").val(html.data);
'html.data' will contain the data that you obtained from your web service, and the call to vall will make sure that it's added to the elements value property.