c# - 我如何从 C# 调用 javascript

标签 c# javascript jquery asp.net

我想在网站上使用带有产品界面的 jQuery 价格范围 slider ,我找到了一些示例,但他们添加了 php,如何使用 c# 调用此 javascript?

<html>
  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <link type="text/css" href="jquery-ui-1.8rc1.custom.css" rel="stylesheet" />

    <script type="text/javascript" src="js/jquery-1.4.1.min.js"></script>

    <script type="text/javascript" src="js/jquery-ui-1.8rc1.custom.min.js"></script>

    <script type="text/javascript">

        $(function() {

            $slider = $("#slider");//Caching slider object

            $amount = $("#amount");//Caching amount object

            $slider.slider({

                range: true, // necessary for creating a range slider

                min: 0, // minimum range of slider

                max: 500, //maximimum range of slider

                values: [75, 300], //initial range of slider

                slide: function(event, ui) { // This event is triggered on every mouse move during slide.

                    $amount.html('$' + ui.values[0] + ' - $' + ui.values[1]);//set value of  amount span to current slider values

                }

            });



            $amount.html('$' + $slider.slider("values", 0) + ' - $' + $slider.slider("values", 1));

        });

    </script>

    <title></title>

    <style type="text/css">

        body{font-size: 12px;font-family:"Arial","Helvetica","Verdana","sans-serif";}

        .left{float:left;}

        .clear{clear:both}

        #wrapper{margin:40px auto;width:940px}

        #leftSlider{width: 200px;margin-right: 30px;}

        #range{margin-bottom: 20px;}

        #products{width:710px}

        #products ul{

            list-style: none;

            margin:0px;padding:0px

        }

        #products ul li{

            margin:4px;

            float:left;

            height:180px;

            width:200px;

            background-color: #333;

            -moz-border-radius:6px;

            -webkit-border-radius:6px;

            -khtml-border-radius:6px;

        }

        #amount{font-size: 14px; text-shadow:0px 1px 0px #ccc}

    </style>

</head>



<body>

    <div id="wrapper">

        <div class="left" id="leftSlider">

            <div id="range">Price Range <span id="amount"></span></div>

            <div id="slider"></div>

        </div>

        <div class="left" id="products">

            <ul>

                <li></li>

                <li></li>

                <li></li>

                <li></li>

                <li></li>

                <li></li>

                <li></li>

                <li></li>

                <li></li>

            </ul>

        </div>

    </div>



 </body>

</html>

最佳答案

来自MSDN docs

public static void RegisterStartupScript(
    Control control,
    Type type,
    string key,
    string script,
    bool addScriptTags
)

参数

control Type: System.Web.UI.Control The control that is registering the client script block.

type Type: System.Type The type of the client script block. This parameter is usually specified by using the typeof operator (C#) or the GetType operator (Visual Basic) to retrieve the type of the control that is registering the script.

key Type: System.String A unique identifier for the script block.

script Type: System.String The script.

addScriptTags Type: System.Boolean true to enclose the script block with and tags; otherwise, false.

这将在客户端生成一个脚本 block 。

关于c# - 我如何从 C# 调用 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6188244/

相关文章:

javascript - 如何制作一个简单的 HTML CSS 时间图

javascript - 如何用jquery找到深度嵌入的 child

c# - WPF 程序启动崩溃 : How to Debug?

c# - Linux相当于Direct draw

c# - 如何在 C# 中的 List<string> 上切换大小写

javascript - 默认加载的选项卡内容

javascript - CKEditor div 元素被替换而不是填充

javascript - 将最后一个表行的选定值复制到新行

c# - 为什么 C# 不允许将 using 变量作为 ref 或 out 传递给函数

javascript - 如何制作交互式 Highcharts 工具提示