use*_*114 1 javascript coldfusion jquery
我有以下jQuery(当前公认的凌乱),它向表中添加了一个新行.但是,它不是插入<cfinput>
字段.事实上,coldfusion正在以某种方式读取javascript块中的标记,因为它会抛出CF错误.
Context validation error for tag cfinput.The tag must be nested inside a cfform tag
Run Code Online (Sandbox Code Playgroud)
如果我将其更改为正常<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();
});
Run Code Online (Sandbox Code Playgroud)
任何帮助赞赏!
您无法通过JavaScript添加CF表单标记.在ColdFusion完成所需的任何处理之后,JavaScript会在浏览器中发生.到那个时候任何是一个CFINPUT标签(或任意ColdFusion标签)现在已经转换为HTML.
如果需要动态地向表单添加字段,只需添加常规的旧HTML表单元素即可.查看浏览器中的源代码,您将看到正在传递给浏览器的内容.JS或浏览器都不知道ColdFusion或CFINPUT是什么.