1

我想在 Windows Phone 浏览器控件中构建手风琴菜单。为此,我正在解析一项休息服务并将其放入列表中。现在我想在我的 html 页面 jQuery 函数中访问该列表。为此,我正在使用以下代码,但无法读取 jQuery 函数中的列表值。

代码:

private void browser_ScriptNotify(object sender, NotifyEventArgs e)
{      
    List<string> str = new List<string>();
    str.Add("Welcome");
    str.Add("Bye");
    browser.InvokeScript("getMemoryUsageCallback", str.ToArray());
}

网页

 <!DOCTYPE html>
      <html lang="en">
    <head>
      <meta charset="utf-8" />
      <title>jQuery UI Accordion - Default functionality</title>
      <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
      <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
      <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
      <link rel="stylesheet" href="/resources/demos/style.css" />

        <script>
            $(function () {
                $("#accordian h1").click()
                {

                }


            });

        </script>
    </head>
    <body>

    <div id="accordion">
      <h3 id="memoryUsageLimit">Section 1</h3>
      <div>
        <p>
        Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
        amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
        odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
        </p>
      </div>
      <h3>Section 2</h3>
      <div>
        <p>
        Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
        purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
        velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In
        suscipit faucibus urna.
        </p>
      </div>
      <h3>Section 3</h3>
      <div>
        <p>
        Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
        Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
        ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis
        lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
        </p>
        <ul>
          <li>List item one</li>
          <li>List item two</li>
          <li>List item three</li>
        </ul>
      </div>
      <h3>Section 4</h3>
      <div>
        <p>
        Cras dictum. Pellentesque habitant morbi tristique senectus et netus
        et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in
        faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia
        mauris vel est.
        </p>
        <p>
        Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
        Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
        inceptos himenaeos.
        </p>
      </div>
    </div>

         <script type="text/javascript">
             function onLoad() {
                 window.external.notify("getMemoryUsage");
             }

             $(function getMemoryUsageCallback(str1) {


                 $(accordion).append("<h3>"+str1.valueOf[0] +"</h3>");
                 $(accordion).accordion();
             });
        </script>


    </body>
    </html>

但我将 str[0] 值设为未定义。请帮我解决这个问题。

并发布一些示例项目链接,我可以在其中使用 C#、JavaScript 和 J-query 在 Windows Phone 移动应用程序中的 Web 浏览器控件中。以及在 Javascript 和 jquery 中访问 C# 变量的任何示例,反之亦然。

4

1 回答 1

0

首先,你没有打电话onLoad()。它不会被神奇地调用。将您的身体标签更新为

<body onload="onLoad();">

也改变你的getMemoryUsageCallback功能如下

function getMemoryUsageCallback() {
    $(accordion).append("<h3>" + arguments[0] + "</h3>");
    $(accordion).accordion();
}

您可以访问arguments内置变量来访问传递的参数。也包括$(function ... });会导致错误,所以只需使用正常的 js 函数声明,如上所示。

完整的html如下:

<!DOCTYPE html>
  <html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Accordion - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />

    <script>
        $(function () {
            $("#accordian h1").click()
            {

            }


        });

    </script>
</head>
<body onload="onLoad();">

<div id="accordion">
  <h3 id="memoryUsageLimit">Section 1</h3>
  <div>
    <p>
    Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
    ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
    amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
    odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
    </p>
  </div>
  <h3>Section 2</h3>
  <div>
    <p>
    Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
    purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
    velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In
    suscipit faucibus urna.
    </p>
  </div>
  <h3>Section 3</h3>
  <div>
    <p>
    Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
    Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
    ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis
    lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
    </p>
    <ul>
      <li>List item one</li>
      <li>List item two</li>
      <li>List item three</li>
    </ul>
  </div>
  <h3>Section 4</h3>
  <div>
    <p>
    Cras dictum. Pellentesque habitant morbi tristique senectus et netus
    et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in
    faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia
    mauris vel est.
    </p>
    <p>
    Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
    Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
    inceptos himenaeos.
    </p>
  </div>
</div>

     <script type="text/javascript">
         function onLoad() {
             window.external.notify("getMemoryUsage");
         }

         function getMemoryUsageCallback() {
             $(accordion).append("<h3>" + arguments[0] + "</h3>");
             $(accordion).accordion();
         }
    </script>


</body>
</html>
于 2013-05-28T07:08:49.053 回答