我有一个表单,可以在数据库上进行查找,查找是使用 load()
完成的。这很好。
我想做的是读取通过 php 返回的输入值。我在想我需要使用 .live()
方法,但我不确定如何。
我当前的代码是:
var recordCount = $("input[name=noOfCusts]").val();
console.log("Number is " + recordCount)
所以input[name=noOfCusts]
是从 PHP 加载的,所以我无法理解它。我只是得到一个未定义的值。
如何将live()滚动到var recordCount = $("input[name=noOfCusts]").val();
谢谢
我的加载代码是
$("input[name=findCust]").keyup(function(){
var key = $(this).val();
var type = 1;
$("div#CustomerResults").html("<img src='../images/loading.gif' alt='loading'/>").delay('500').load("../../ajax/customerFinder.php",{"key":key,"type":type}).fadeIn(300);
//#############################################
// Extra bit to make the search form work with a return
$("input[name=findCust]").live('keyup',function(){
var recordCount = $("input[name=noOfCusts]").val();
console.log("Number is " + recordCount)
});
//var recordCount = $("input[name=noOfCusts]").find("input[name=noOfCusts]").val();
//
//$('input[name="noOfCusts"]').val(data);
//console.log("Number is " + data)
//#############################################
});
不要返回 HTML input
标记,而只返回 HTML DOM 中已存在的该输入的值。
然后在成功时加载调用中将获取的值设置为该输入:
// success
$('input[name="noOfCusts"]').val(data);
alert(data);