使用ajax的Jquery自动建议
Jquery autosuggest with ajax
我正在尝试实现一种自动建议与动态添加的输入框一起工作的方式。静态输入类型的一切都很好。我能够使用静态输入类型通过ajax请求和检索结果。但当我试图对动态输入做同样的事情时,它不起作用——这是我的代码。任何帮助都将不胜感激。
<script src="js/jquery.js"></script>
<script src="js/jquery.autoSuggest.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script type="text/javascript">
$.noConflict();
jQuery(function(){
var rows = 0;
jQuery('#addRow').click(function(){
jQuery('#userRows').append('<div class="userRow"><input type="text" name="users['+rows+'][name]" /><input type="text" name="country" id="inputBox" /><input type="text" name="id-holder" id="id-holder"> <input type="text" id="price" name="users['+rows+'][price]" /><a href="javascript:;" class="removeRow">Remove</a> name="users['+rows+'][name]"<div>');
rows++;
location.reload();
});
jQuery(document).on('click', '.removeRow', function(){
jQuery(this).closest('.userRow').remove();
});
// Below just used to show the string on submit
});
</script>
<script type="text/javascript">
<?php
$pluginConf = "";
if(isset($_GET) && count($_GET) > 0){
extract($_GET);
if($limit == "") $limit = "10";
if($width == "") $width = "auto";
$pluginConf = '
$(function() {
$("#inputBox").autoSuggest({
ajaxFilePath : "server.php",
ajaxParams : "dummydata=dummyData",
autoFill : "'.$autofill.'",
iwidth : "'.$width.'",
opacity : "0.9",
ilimit : "'.$limit.'",
idHolder : "id-holder",
prices : "price",
match : "'.$match.'"
});
alert("Worked");
});';
} else {
$pluginConf = '
$(function() {
$("#inputBox").autoSuggest({
ajaxFilePath : "server.php",
ajaxParams : "dummydata=dummyData",
autoFill : false,
iwidth : "auto",
opacity : "0.9",
ilimit : "10",
idHolder : "id-holder",
prices : "price",
match : "contains"
});
alert("Worked");
}); ';
}
echo $pluginConf;
?>
</script>
</head>
<body>
<div>
Item Name @ Price
</div>
<form method="post" id="usersForm">
<div id="userRows">
<a href="javascript:;" id="addRow">Add Row</a><br />
</div>
<input type="submit" id="submit" value="Submit" />
<!--<input type="text" name="xxx" id="inputBox">
<input type="text" name="id-holder" id="id-holder">
<input type="text" name="price" id="price"> -->
</form>
</body>
</html>
https://github.com/wuyuntao/jquery-autosuggest/blob/master/jquery.autoSuggest.js
查看代码,它似乎只将这些事件(焦点)附加到页面加载时创建的元素上。您将需要编写一些额外的代码来向生成的输入元素添加"建议"。
https://api.jquery.com/on/使用此功能。
相关文章:
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 将curl查询转换为jQuery.ajax()
- jQuery AJAX write to XML
- jQuery Ajax GET请求工作不正常
- jquery ajax https调用给出ERR_INSECURE_RESPONSE
- VB NET JQUERY AJAX上出现错误500
- 如何使用jquery ajax和jsonp在您自己的域上读取json数据
- Jquery/Ajax.serialize()未完全工作
- 页面加载之前的jQuery Ajax加载程序
- jquery/ajax无限滚动事件
- 使用Jquery$.ajax将json数据传递给servlet(doPost)
- 如何将给定的curl命令复制为jquery ajax请求
- 使用 JQUERY AJAX (Spring MVC) 从控制器中删除
- Twitter API在jQuery AJAX中设置授权头
- AngularJS JQuery Ajax表单提交等效
- jQuery Ajax.ajaxSuccess()事件未激发
- 为什么Jquery$.ajax在函数调用中触发所有statusCode,即使调用成功
- jQuery AJAX总是出错
- jQuery Ajax数组序列化错误
- jQuery AJAX获取Vimeo缩略图