我有以下jQuery (诚然目前比较混乱),它将一个新行追加到一个表中。但是,它没有插入<cfinput>字段。实际上,不知何故,coldfusion正在读取javascript块中标记,因为它抛出了CF错误。
Context validation error for tag cfinput.The tag must be nested inside a cfform tag如果我将其更改为普通的<input>,那么问题就会消失,字段就会被插入。
我需要<cfinput>来使用ColdFusion的原生日期选择器。不管怎样,我很好奇为什么会发生这样的事情。
$(".aAddLine").click(function(e){
var clickedID = $(this).attr("id");
var lineNo = parseInt(clickedID.split("_")[1])
var newLineNo = parseInt(lineNo+1)
var x = "";
$('#tdPlus_' + lineNo).html("");
x += '<tr>';
x += '<td width="50" class="tdPlus' + newLineNo + '"><a class="aAddLine" id="aAddLine_' + newLineNo + '" href="##">+ Line</a></td>';
x += '<td valign="top">Date</td>';
/*issue with the <cfinput> on the line below */
x += '<td><cfinput class="dt validate" type="datefield" name="startDate" id="startDate_' + newLineNo + '" validate="eurodate" mask="dd/mm/yyyy" /> <span class="res" id="resStartDate_' + newLineNo + '"> <span class="hint"></span></span></td>';
x += '<td style="width:10px"> </td>';
x += '<td>Time</td>'
x += '<td><input class="validate" type="datefield" name="startTime_' + newLineNo + '" id="startTime_' + newLineNo + '" style="width:35px;"/> <span class="res" id="resStartTime_' + newLineNo + '"></span> to <input class="validate" type="datefield" name="endTime_' + newLineNo + '" id="endTime_' + newLineNo + '" style="width:35px;"/> <span class="res" id="resEndTime_' + newLineNo + '""></span></td>'
x += '</tr>'
$('#tblItem > tbody:last').append(x);
e.preventDefault();
e.stopPropagation();
});感谢任何人的帮助!
发布于 2011-11-03 13:14:38
您不能通过JavaScript添加CF表单标签。在ColdFusion完成了它需要做的任何处理之后很长一段时间,浏览器中才会发生JavaScript。到那时,任何曾经是CFINPUT标记(或任何ColdFusion标记)的内容现在都已转换为HTML语言。
如果需要向表单动态添加字段,只需添加常规的旧HTML表单元素即可。查看浏览器中的源代码,您将看到这就是交付给浏览器的内容。JS和浏览器都不知道什么是ColdFusion或CFINPUT。
发布于 2011-11-04 03:35:56
我假设包含JS的页面是一个ColdFusion页面,因此它尝试使用"
就像其他人所说的那样,在那个级别使用aJax是行不通的,你应该只使用jQuery插件或者通过cfinput或者其他方式来获取内容。
发布于 2011-11-03 13:26:38
CFINPUT是coldfusion标签和进程,当ColdFusion页面正在编译时,当你试图通过jQuery (使用javascript)添加它时,它不会被ColdFusion处理,因为你是在浏览器级别工作的,服务器对此一无所知。在这种情况下,CFINPUT不是有效的HTML标记。
https://stackoverflow.com/questions/7990410
复制相似问题