我想在删除对象之前对屏幕进行确认,但是 return 语句总是带有下划线。我该如何解决这个问题?
{% if notifications %}
{% for not in notifications %}
<li>
<figure><img src="{{not.object.image.url}}" alt=""></figure>
<small>{{not.object.category.name}}</small>
<h4>{{not.object.title}}</h4>
<p>{{not.message}}</p>
<!-- <p><a href="#0" class="btn_1 gray"><i class="fa fa-fw fa-eye"></i> View course</a></p> -->
<ul class="buttons">
<li><a onclick="return confirm('Are you sure?');" href="{% url 'deleteNotificationsAdmin' not.pk %}" class="btn_1 gray delete wishlist_close" >
<i class="fa fa-fw fa-times-circle-o"></i> Delete</a></li>
</ul>
</li>
{% endfor %}
{% endif %}
Run Code Online (Sandbox Code Playgroud)
当我用鼠标悬停在它上面时,会出现错误
“return”语句只能在函数体内使用。
因此,事实证明错误实际上是 Visual Studio Code 中的一个错误,目前计划于2022 年 3 月 MilestoneA \'return\' statement can only be used within a function body.修复。
根据HTML 5.2: 7.4return value ,与事件处理程序一起使用是有效的。
\n\n处理返回值如下:
\n\n
\n- \n
如果事件类型是 mouseover
\n- \n
如果事件类型为 error 并且 E 是 ErrorEvent 对象
\n\n
\n- 如果返回值为 Web IDL 布尔 true 值,则取消该事件。
\n- \n
如果事件类型是 beforeunload
\n\n
\n- \n
注意:事件处理程序 IDL 属性\xe2\x80\x99s 类型为 OnBeforeUnloadEventHandler,因此返回值将被强制转换为 null 值或 DOMString。
\n- \n
如果返回值为null,则取消该事件。
\n- \n
否则,如果事件对象 E 是 BeforeUnloadEvent 对象,并且事件对象 E\xe2\x80\x99s returnValue 属性\xe2\x80\x99s 值为空字符串,则设置 returnValue 属性\xe2\x80\x99s 值返回值。
\n- \n
否则如果返回值为 Web IDL 布尔假值,则取消该事件。
\n
作为解决方法,您可以禁用html.validate.scriptsVisual Studio Code 设置中的选项。