cflayout:getElementById 在包含在源文件中时不起作用
如果我使用 cflayout 在 CF9 中创建一个布局,如下所示:
<cfajaximport tags="cfform">
<cflayout type="border" name="example">
<cflayoutarea position="center" name="_center" source="/example/center.cfm" />
</cflayout>
然后创建一个要包含的 center.cfm 文件:
<cfform name="myForm" id="myForm" action="post">
<cfinput name="field1" type="text"><br/>
</cfform>
<script>
ThisForm = document.getElementById('myForm');
alert(ThisForm.id);
</script>
我收到错误:
Error processing JavaScript in markup for element cf_layoutarea_center
但如果我将 center.cfm 的内容移动到标签中(并删除源参数)代码按预期工作。谁能告诉我如何使用 center.cfm 文件让它工作?或者解释一下为什么这不起作用?
感谢您抽出时间。
干杯 标记
If I create a layout in CF9 using cflayout as below:
<cfajaximport tags="cfform">
<cflayout type="border" name="example">
<cflayoutarea position="center" name="_center" source="/example/center.cfm" />
</cflayout>
and then create a center.cfm file to be included:
<cfform name="myForm" id="myForm" action="post">
<cfinput name="field1" type="text"><br/>
</cfform>
<script>
ThisForm = document.getElementById('myForm');
alert(ThisForm.id);
</script>
I get an error:
Error processing JavaScript in markup for element cf_layoutarea_center
But if I move the contents of center.cfm into the tag (and remove the source parameter) the code works as expect. Can anyone tell me how I can get this to work using the center.cfm file? Or explain why this doesn't work?
Thanks for your time.
Cheers
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 ID 名称值调用函数参数。
我使用 ID 值调用 javascript 函数,然后将 ID 值与 getElementByID 一起使用:
Call function argument with ID name value.
I call the javascript function with ID value, then use ID value with getElementByID:
(丹已经提供了答案。但只是为了表明它可以工作..)
这对我来说在 CF9 下工作得很好。我不确定为什么添加标签对您不起作用。
test.cfm
myForm.cfm
(Dan provided the answer already. But just to show it can work ..)
This worked fine for me under CF9. I am not sure why adding the tags did not work for you.
test.cfm
myForm.cfm
您需要使用
AjaxOnLoad
ColdFusion 方法,以便在子页面加载完成后触发 JavaScript。您需要在 center.cfm 中像这样定义您的函数:然后,在 center.cfm 中的任何位置添加以下 ColdFusion:
一旦 center.cfm 完成加载,就会触发
myLoadFunction
cflayout
标签。编辑: Adobe LiveDocs 有一个关于如何处理动态包含的 javascript。
相关部分:
You need to use the
AjaxOnLoad
ColdFusion method in order to fire off your javascript once the child page finishes loading. You need to define your function like this inside of center.cfm:Then, anywhere in center.cfm, add the following ColdFusion:
That should fire the
myLoadFunction
as soon as center.cfm has finished loading in yourcflayout
tag.EDIT: The Adobe LiveDocs has a section on how to handle dynamically included javascript.
The relevant section:
对我来说,center.cfm 文件需要有 html、body 和 body 标签似乎不太正确,所以我尝试了这个(Dan 和 Leigh 的解决方案的组合):
主页:
然后 center.cfm 很简单:
这按预期工作,并且我们不会在通过 AJAX 加载并添加到页面的内容中发送另一个 html 标签等。
It did not seem right to me that the center.cfm file needed to have the html, body and body tags, so I tried this (a combination of Dan & Leigh's solutions):
Main Page:
And then center.cfm is simply:
THis works as expected, and we are not sending another html tag, etc in content that is being loaded via AJAX and added to the page.