当从jQuery .get()调用返回时,我遇到了cfinput标记的问题。如果我将标签放在主页上,如下所示:
<cfform>
<cfinput type="text" name="txtinputfilter" autosuggest="cfc:#Application.cfcDir#autoSuggest.lookupTailNumber({cfautosuggestvalue})" >
标签正确加载,自动提示功能正常工作。但是,如果我将完全相同的标记(而不是其他标记)放在一个名为common/includes/FilterData.cfm的单独模板中,并从主页调用它,如下所示:
<div id="txt_input_container"></div>
$(document).ready(function(){
//the following get call is normally called on another select input's onchange
$.get('common/includes/FilterData.cfm',
//note that the following parameters are not being used in this example
{column: selectedValue,
filterValue: filterValue,
filterID: filterID,
configFile: 'Tracking/config/GeneralMaint.xml'},
function(response){
$('#txt_input_container').empty().append(response);
}
);
});加载标记,但自动建议不起作用。控制台显示我的get后面紧跟着八个调用:
http://localhost/CORE/common/includes/FilterData.cfm?column=SERIAL_NUMBER&filterValue=&filterID=fi_1&configFile=Tracking%2Fconfig%2FGeneralMaint.xml
http://localhost/CFIDE/scripts/ajax/yui/yahoo-dom-event/yahoo-dom-event.js?_=1318592952367
http://localhost/CFIDE/scripts/ajax/yui/animation/animation-min.js?_=1318592952634
http://localhost/CFIDE/scripts/ajax/yui/autocomplete/autocomplete-min.js?_=1318592952706
http://localhost/CFIDE/scripts/ajax/messages/cfmessage.js?_=1318592952745
http://localhost/CFIDE/scripts/ajax/package/cfajax.js?_=1318592952782
http://localhost/CFIDE/scripts/ajax/package/cfautosuggest.js?_=1318592952821
http://localhost/CFIDE/scripts/cfform.js?_=1318592952859
http://localhost/CFIDE/scripts/masks.js?_=1318592952907后跟此错误消息:
_cf_resetLoadingIcon_1318592952305 is not defined
[Break On This Error] /* ]]> */</script> 发布于 2011-10-15 02:03:55
这不会是你想要听到的答案。
为了动态显示jQuery .get()操作的结果,并使新的javascript生效,必须在初始.get()的结果处理程序期间绑定影响新显示的jQuery的事件。通常,这是doable...something,大致如下:
$.get('common/includes/FilterData.cfm',
{column: selectedValue},
function(response){
$('input').change(function(event){
...addtl. logic here
}您将找到一种方法,在将change事件绑定到作为初始.get()调用加载的全新输入字段的绑定中,指向/调用您的新函数。
当涉及到CFML时,事情就变得混乱了。cfform/cffinput,当与you...automatically的自动提示parameter...build一起使用时,手动输入javascript。但是,对于这段代码的生成并没有真正的控制--CF会任意命名它。当我输入你的代码进行测试时,我得到了一个名为_cf_autosuggest_init_1318614417652...is的函数,对你来说是一样的吗?(可能不会)。
因此,如果您不知道事件处理程序将被调用什么,那么在.get()的结果上动态绑定新的事件处理程序将非常困难。
我的建议是要么重新设计您的.get()调用,使您不加载cfform/cfinput--而是加载原始数据本身--并将输入保留在父模板上,或者(深呼吸)……
...scrap cfform/cfinput,并手动编写jQuery自动提示功能,这样您就可以控制函数的名称--当需要动态绑定它们时,可以在jQuery结果处理程序中指向它们。
https://stackoverflow.com/questions/7767381
复制相似问题