我想显示一些信息(在jquery对话框中),所以当用户在文本框和模糊中输入一个值时,应该使用该值进行ajax调用并在对话框中显示信息。
这是我到目前为止所尝试的:
$(function () {
$('#MyTextbox').blur(function () {
var id = $(this).val();
if (id >= "1") {
alert(id);
ShowData();
}
});
});
function ShowData() {
$("#dialog").dialog();
}
还有其他更好的方法吗?
答案 0 :(得分:1)
$(function () {
$("#dialog").dialog({ isOpen : false});//Create Dialog
$('#MyTextbox').blur(function () {
var id = parseInt($(this).val()); //See correction here
if(id >= 1) {
//Get content and append to dialog
$("#dialog").dialog("open");//Open dialog
}
});
});
答案 1 :(得分:0)
如果你在php中有一个ajax脚本,你可以直接从blur事件函数调用它并将html结果传递给对话框。
$('#MyTextbox').blur(function () {
// the ajax call
$.get('ajaxScript.php',{id: $("this").val()},
function(data){
//the result in html to the dialog
$("#dialog").empty().append(data).dialog();
},'html');
});
希望这会有所帮助