javascript 块内的字符串会导致问题

发布于 2024-12-13 10:09:58 字数 2167 浏览 1 评论 0 原文

我有以下 jQuery(目前确实很混乱),它将新行附加到表中。但是,它不会插入 字段。事实上,coldfusion 正在以某种方式读取 javascript 块内的该标签,因为它会引发 CF 错误。

Context validation error for tag cfinput.The tag must be nested inside a cfform tag

如果我将其更改为正常的 ,那么问题就会消失并且该字段将被插入。

我需要 来使用 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();
            });

任何帮助表示赞赏!

I have the following jQuery (admittedly messy at the moment) which appends a new row to a table. However, it's not inserting the <cfinput> field. In fact, somehow coldfusion is reading that tag inside the javascript block because it throws a CF error.

Context validation error for tag cfinput.The tag must be nested inside a cfform tag

If I change it to a normal <input>, then the problems go away and the field is inserted.

I need the <cfinput> to make use of ColdFusion's native date picker. Regardless, I'm curious why this is happening.

    $(".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();
            });

Any help appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

囍笑 2024-12-20 10:09:58

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

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

You cannot add CF form tags via JavaScript. JavaScript happens in the browser LONG after ColdFusion has done any processing it needs to do. By that time anything that was a CFINPUT tag (or any ColdFusion tag) has now been converted to HTML.

If you need to dynamically add fields to a form, just add regular old HTML form elements. Look at the source code in the browser and you will see that is what is being delivered to the browser. Neither JS or the browser have any idea what ColdFusion or CFINPUT are.

半岛未凉 2024-12-20 10:09:58

我假设包含 JS 的页面是 ColdFusion 页面,因此它尝试解析带有“是一个有效的 ColdFusion 标记,并且它不在 cfform 内,从而使代码无效,因此当 CF 第一次尝试渲染您的页面时,它会出错。

就像其他人所说的那样,在该级别拥有 cfinput 是行不通的,您应该只使用 jQuery 插件或获取 的内容。通过 aJax 或其他方式。

I’m assuming the page that contains the JS is a ColdFusion page, so it tries to parse anything with "<CF". Looking at your code, cfinput is a valid ColdFusion tag and it’s not within a cfform making the code invalid, so when CF tries to render your page for the first time it errors.

Like the others have stated, having a cfinput at that level won't work and you should just use a jQuery plugin or get the contents of the <cfinput> via aJax or some other way.

白首有我共你 2024-12-20 10:09:58

CFINPUT 是 ColdFusion 标签,在 ColdFusion 页面编译时进行处理,当您尝试通过 jQuery 添加它(使用 javascript)时,它不会由 ColdFusion 处理,因为您在浏览器级别工作,而服务器对此一无所知这。在这种情况下,CFINPUT 不是有效的 HTML 标记。

CFINPUT is coldfusion tag and process at the time of ColdFusion page is compiling and when you are try to add it through jQuery (Using javascript) it doesn't process by ColdFusion as you are working at Browser level and Server do not have any idea about this. And in this case CFINPUT is not a valid HTML tag.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文