如何从 Script# 代码访问 html 函数?

How to access html function from Script# code?

在 Script# 中,如何访问页面上 html 中定义的函数?

html 页面上有这个预先存在的函数:

<script type='text/javascript'>
    function makeStuffHappen(selector)
    {
           alert('stuff happening');
    }
</script>
<div id='#usefulplace'></div>

我从 scriptsharp 加载生成的脚本,需要访问该生成脚本中的 "Global" makeStuffHappen 函数。基本上,从 Scriptsharp 我需要能够调用该函数 makeStuffHappen("#usefulplace");

如何从 scriptsharp 内部调用 makeStuffHappen?

我知道怎么做了。我创建了一个 scriptsharp class 文件,并执行了 IgnoreNamespace、Imported 和 ScriptAlias 这三个文件,以使其映射到 html 中的函数,如下所示:

using System.Runtime.CompilerServices;

namespace TestNamespace
{
    /// <summary>
    /// 
    /// </summary>
    [IgnoreNamespace]
    [Imported]
    public static class ImportedPageFunctions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="selector"></param>
        [ScriptAlias("makeStuffHappen")]
        public static void makeStuffHappen(string selector)
        {

        }
    }
}