gpt4 book ai didi

HTML 属性中的 JavaScript 片段 : special characters

转载 作者:行者123 更新时间:2023-12-03 06:58:45 25 4
gpt4 key购买 nike

我在我的应用程序中使用 AngularJS 1.4。我的 HTML 模板中有一些使用逻辑运算符的属性,例如:

<p ng-if="!edit.model && !model.length">...</p>

我的文本编辑器将 && 标记为错误,大概是因为它不是 HTML 转义的。我真的应该将其更改为 && 吗?这不像我使用 ambiguous ampersand .

最佳答案

Should I really change it to &amp;&amp;?

没有。从来没有。
或者是的,如果您的优先级是当前编辑器语法引擎而不是应用程序的功能。

My text editor marks the && as an error, presumably because it's not HTML-escaped.

因为它愚蠢HTML Codes太过保护(通才) .

<小时/>

这是您提出的一个有效问题,让我们看一些示例:

会工作很好:
<p>
<input type="checkbox" id="hello" ng-model="hello">
<label for="hello">Say only Hello!</label>
</p>
<p>
<input type="checkbox" id="goodbye" ng-model="goodbye">
<label for="goodbye">Say only Goodbye!</label>
</p>
<h1 ng-show="hello&&!goodbye">Hello!</h1>
<h1 ng-show="!hello&&goodbye">Goodbye!</h1>

参见https://plnkr.co/edit/93LAQJJ1bwTNPteLCv5Q?p=preview .

但是,这 不会:
[..]
<p>
<input type="checkbox" id="not" ng-model="not">
<label for="not">Say only Not!</label>
</p>
<h1 ng-show="hello&&!not">Hello!</h1>
<h1 ng-show="!hello&&not">Not!</h1>

参见https://plnkr.co/edit/HRVigpQCCg1hQCW25Xgk?p=preview .

但是,这 将会:
<p>
<input type="checkbox" id="not" ng-model="not">
<label for="not">Say only Not!</label>
</p>
<h1 ng-show="hello && !not">Hello!</h1>
<h1 ng-show="!hello && not">Not!</h1>

参见https://plnkr.co/edit/u3uNt9xHMnvtI0HZynlJ?p=preview .

只要您不输入包含 HTML 代码的值就可以了。

关于HTML 属性中的 JavaScript 片段 : special characters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37151994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com