javascript - 没有类型的cshtml脚本标签

标签 javascript jquery razor types tags

我对 ASP.NET 和前端技术总体来说是新手。我有以下代码:

<ul>
    @foreach (var item in Model)
    {
        <li>
            <img src="@item" alt="file here" width="100" height="100" />
            <a id="@item" href="#" onclick="deleteFile('@item');">Delete</a>
        </li>
    }
</ul>

<script>
    function deleteFile(item) {
        var url = "/Home/DeleteFile";
        $.post(url, { Name: item }, function (data) {
            window.location.href = "/Home/Upload";
        });
    }
</script>

我知道我们可以通过类型标签识别编写脚本所用的语言。例如

<script type="text/javascript"...

但是如果不指定这个类型,我如何识别脚本的语言呢?此外,在脚本中,post 语句中的参数“function(data)”是做什么的,该函数的数据参数来自哪里?

谢谢!

最佳答案

参见the HTML specification :

The type attribute gives the language of the script or format of the data. If the attribute is present, its value must be a valid MIME type. The charset parameter must not be specified. The default, which is used if the attribute is absent, is "text/javascript".

关于javascript - 没有类型的cshtml脚本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25346745/

相关文章:

javascript - TinyMCE iframe 不显示

JavaScript:从服务器获取更新?

javascript - 用 z-index 确定最近的元素?

asp.net - Razor 语法高亮

javascript - 当我在真正存在的引用中使用 appendChild ("<br>"时发生错误

javascript - 如何在css3中将小圆圈添加到大圆圈中?

javascript - 无法读取 VUE 中链式 AXIO 事务内的公共(public)数组项

jquery - 为什么在调整页面大小时( Bootstrap )我的部分 html 代码消失了?

asp.net-mvc - MVC3 Razor 中 Page.Form.DefaultFocus 的等价物是什么?

c# - 从开始作业日期开始在 mvc 表中显示天数