ColdFusion 从另一个文件调用 bootstrap 模态
ColdFusion calling a bootstrap modal from another file
如果我的项目在不同的文件中 (modals.cfm),我将创建所有模态框。如何从另一个文件中调用模态?
modals.cfm(一个bootstrap模态示例)
<div class="modal fade" id="requestError" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button aria-hidden="true" data-dismiss="modal" class="close" type="button">X</button>
<h4 id="myModalLabel1" class="modal-title"><strong>Error!</strong></h4>
</div>
<div class="modal-body">
<div class="alert alert-danger fade in">
<h2 id="error"></h2>
</div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
<button data-dismiss="modal" class="btn btn-primary" type="button" onClick="myFunc();">Confirm</button>
</div>
</div>
</div>
然后,我想从另一个 cfm 文件中调用它。例如,index.cfm:
<button type="button" class="btn btn-primary" onClick="callModal();"> Test </button>
<script>
function callModal(){
$("#error").html("My custom error message");
$("#requestError").modal(); // How can I call it from another file?
}
</script>
可能吗?
谢谢
其中一个 "fundamental" 帮助我理解 ColdFusion 的事情是这样想的:ColdFusion 的目的是生成 HTML.
现在,根据您的描述,您说您想要使用在 modals.cfm
中生成的 HTML。很好,但是如何插入到您现在所在的页面上(例如:index.cfm
)?
一个简单直接的方法是在 index.cfm
到 modals.cfm 上执行 CFINCLUDE:
<!-- index.cfm code here--->
<button type="button" class="btn btn-primary" onClick="callModal();"> Test </button>
<cfinclude template="modals.cfm">
<script>
function callModal(){
$("#error").html("My custom error message");
$("#requestError").modal(); // How can I call it from another file?
}
</script>
如果你想通过 AJAX 加载页面(如 James 上面提到的),这将需要更多的工作,但绝对可行。我们只需要更多代码。
如果我的项目在不同的文件中 (modals.cfm),我将创建所有模态框。如何从另一个文件中调用模态?
modals.cfm(一个bootstrap模态示例)
<div class="modal fade" id="requestError" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button aria-hidden="true" data-dismiss="modal" class="close" type="button">X</button>
<h4 id="myModalLabel1" class="modal-title"><strong>Error!</strong></h4>
</div>
<div class="modal-body">
<div class="alert alert-danger fade in">
<h2 id="error"></h2>
</div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
<button data-dismiss="modal" class="btn btn-primary" type="button" onClick="myFunc();">Confirm</button>
</div>
</div>
</div>
然后,我想从另一个 cfm 文件中调用它。例如,index.cfm:
<button type="button" class="btn btn-primary" onClick="callModal();"> Test </button>
<script>
function callModal(){
$("#error").html("My custom error message");
$("#requestError").modal(); // How can I call it from another file?
}
</script>
可能吗?
谢谢
其中一个 "fundamental" 帮助我理解 ColdFusion 的事情是这样想的:ColdFusion 的目的是生成 HTML.
现在,根据您的描述,您说您想要使用在 modals.cfm
中生成的 HTML。很好,但是如何插入到您现在所在的页面上(例如:index.cfm
)?
一个简单直接的方法是在 index.cfm
到 modals.cfm 上执行 CFINCLUDE:
<!-- index.cfm code here--->
<button type="button" class="btn btn-primary" onClick="callModal();"> Test </button>
<cfinclude template="modals.cfm">
<script>
function callModal(){
$("#error").html("My custom error message");
$("#requestError").modal(); // How can I call it from another file?
}
</script>
如果你想通过 AJAX 加载页面(如 James 上面提到的),这将需要更多的工作,但绝对可行。我们只需要更多代码。