简体   繁体   English

使用字体 Awesome Unicode 和 Coldfusion

[英]Using Font Awesome Unicode with Coldfusion

I have an HTML input button in my ColdFusion application that is submitting a form.我在提交表单的 ColdFusion 应用程序中有一个 HTML 输入按钮。 I am trying to include a Font Awesome icon along with the text of the button.我正在尝试在按钮文本中包含一个 Font Awesome 图标。 The only way I can specify the Unicode without throwing an error is to double out the hash character.我可以指定 Unicode 而不会引发错误的唯一方法是将 hash 字符加倍。

<input class="stylized_btn" tabindex="0" type="submit" name="save2" 
    id="save2" value=" &##xf0c7; Save This Ticket" 
    onclick="disableSaveButtonClick(event);" />

However, instead of showing the icon, it just shows a square.但是,它不显示图标,而是显示一个正方形。 在此处输入图像描述

This seems like it's a quirk with ColdFusion not recognizing my Unicode character because of the double hashtag, but that's just a guess.这似乎是一个怪癖,ColdFusion 由于双标签而无法识别我的 Unicode 字符,但这只是一个猜测。 I have other button elements on my page that are properly displaying the Font Awesome icons correctly, so I know it is not an issue with my font definition.我的页面上有其他按钮元素可以正确显示 Font Awesome 图标,所以我知道这不是我的字体定义的问题。 I am unsure where exactly I am going wrong here.我不确定我到底哪里出错了。 Can anyone help shed some light?任何人都可以帮忙阐明一下吗?

Updated code using button tag instead.改为使用按钮标签更新代码。

HTML button HTML按钮

<button id="saveOnlyButton" name="save" class="stylized_btn">
    <i class="fas fa-save"> </i> Update Ticket
</button> 

在此处输入图像描述

JavaScript JavaScript

window.onload=function(){
    var SaveButton = document.getElementById("saveOnlyButton");
    SaveButton.addEventListener("click", disableSaveButton);
    }

    //Save Button Logic
        function disableSaveButton() {
            console.log("Save button clicked");
            document.getElementById("submitType").value = "save";
            document.getElementById("saveOnlyButton").innerHTML = "Please Wait...";
            document.getElementById("saveOnlyButton").disabled = true;
            document.getElementById("autoSumForm").submit();
        }   

Have you tried using a BUTTON tag?您是否尝试过使用 BUTTON 标签? (We stopped using input:submit buttons.) (我们停止使用 input:submit 按钮。)

We usually use <button type =“submit”><i class=“fa fa-lg fa-my-icon”></i > Label Text</button> , but you should be able to use the HTML entity.我们通常使用<button type =“submit”><i class=“fa fa-lg fa-my-icon”></i > Label Text</button> ,但您应该可以使用 HTML 实体。

Instead of using an input element, use a button.不要使用输入元素,而是使用按钮。 The default behavior of a button is to submit a form.按钮的默认行为是提交表单。

<button class="stylized_btn btn-default" tabindex="0" id="save2" onclick="disableSaveButtonClick(event);"><i class="fa fa-save"></i> Save This Ticket</button>

(I added btn-default in case you're using bootstrap) (我添加了 btn-default 以防您使用引导程序)

It's not a quirk in ColdFusion as you suggest.正如您所建议的,这不是 ColdFusion 中的怪癖。 ColdFusion is behaving exactly as intended. ColdFusion 的行为完全符合预期。 The reason why you need a double hash ## is because whenever you are in a <cfoutput> tag, ColdFusion sees the single hash # as the start of a variable or evaluable expression.您需要双 hash ##的原因是因为每当您在<cfoutput>标记中时,ColdFusion 将单个 hash #视为变量或 evalu 表达式的开始。 When it doesn't find the closing hash, it throws an error.当它没有找到关闭的 hash 时,它会抛出一个错误。

Now there are times when your intent is to use the hash for display purposes and not to evaluate a variable or expression, as it is in your case.现在有时您的意图是将 hash 用于显示目的,而不是像您的情况那样评估变量或表达式。 So the solution is to use the double hash ## an an escape character to let CF know you want to just display it as a single hash on the rendered page.所以解决方案是使用双 hash ##一个转义字符让 CF 知道您只想在渲染页面上将其显示为单个 hash。

If you use your browser's developer tools and inspect element, it shold appear to correctly display as a single hash.如果您使用浏览器的开发人员工具并检查元素,它应该会正确显示为单个 hash。 The other fix to your issue is to make sure you remove the section of code with the input button from being inside a <cfoutput> block.解决问题的另一个方法是确保从<cfoutput>块中删除带有输入按钮的代码部分。

Most importantly, you shouldn't be debugging by looking at the CF source code, you should debug this looking at the rendered page by using your browser's developer tools or the browser's "view source" option.最重要的是,您不应该通过查看 CF 源代码进行调试,您应该使用浏览器的开发人员工具或浏览器的“查看源代码”选项查看呈现的页面来调试它。 If you can, please update your original question by providing a screenshot of the "inspect element" of your submit button.如果可以,请通过提供提交按钮的“检查元素”的屏幕截图来更新您的原始问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM