<cfinput> javascript块中的字符串导致问题</cfinput>

时间:2011-11-03 04:52:02

标签: javascript jquery coldfusion

我有以下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" />&nbsp;<span class="res" id="resStartDate_' + newLineNo + '"> <span class="hint"></span></span></td>';
                x += '<td style="width:10px">&nbsp;</td>';
                x += '<td>Time</td>'
                x += '<td><input class="validate" type="datefield" name="startTime_' + newLineNo + '" id="startTime_' + newLineNo + '" style="width:35px;"/>&nbsp;<span class="res" id="resStartTime_' + newLineNo + '"></span>&nbsp;to&nbsp;<input class="validate" type="datefield" name="endTime_' + newLineNo + '" id="endTime_' + newLineNo + '" style="width:35px;"/>&nbsp;<span class="res" id="resEndTime_' + newLineNo + '""></span></td>'
                x += '</tr>'
                $('#tblItem > tbody:last').append(x);
                e.preventDefault();
                e.stopPropagation();
            });

任何帮助表示赞赏!

3 个答案:

答案 0 :(得分:6)

您无法通过JavaScript添加CF表单标记。在ColdFusion完成所需的任何处理之后,JavaScript会在浏览器中发生。到那时, CFINPUT标签(或任何ColdFusion标签)的任何内容现在都已转换为HTML。

如果需要动态地向表单添加字段,只需添加常规的旧HTML表单元素即可。查看浏览器中的源代码,您将看到正在传递给浏览器的内容。 JS或浏览器都不知道ColdFusion或CFINPUT是什么。

答案 1 :(得分:2)

我假设包含JS的页面是ColdFusion页面,因此它尝试使用“&lt; CF”解析任何内容。查看代码,cfinput 是一个有效的ColdFusion标记,并且在cfform中使代码无效,因此当CF尝试首次呈现您的页面时出现错误

就像其他人所说的那样,在该级别拥有cfinput将无法正常工作,您应该只使用jQuery插件或获取&lt; cfinput&gt;的内容。通过aJax或其他方式。

答案 2 :(得分:0)

CFINPUT是coldfusion标签和ColdFusion页面编译时的过程,当你尝试通过jQuery添加它时(使用javascript)它不会被ColdFusion处理,因为你在浏览器级别工作而服务器没有对此有任何想法。在这种情况下,CFINPUT不是有效的HTML标记。