jquery 在 runat=server 形式中不起作用

标签 jquery asp.net

我在使用 runat=server 子句在表单标记内显示图表时遇到问题。如果我删除子句图表就可以了。我还尝试在 jquery 定义中使用 <%=container%> 除了 #container 之外,但它没有帮助。这是我带有 runat 子句的代码。如果您有任何想法问题出在哪里,我将非常感谢您的回答,谢谢!

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="chart_test.aspx.cs" Inherits="WebUI_Commisions.CS3500.CS3510.chart_test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title></title>
  <script src="jquery-2.1.4.min.js" type="text/javascript"></script>
 </head>
 <body>

<form id="form1" runat="server">
  <div>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>
    <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
  </div>
</form>

<script type="text/javascript">
  $(function () {
    $('#container').highcharts({
      chart: {
        type: 'column'
      },
      title: {
        text: 'Monthly Average Rainfall'
      },
      subtitle: {
        text: 'Source: WorldClimate.com'
      },
      xAxis: {
        categories: [
        'Jan',
        'Feb',
        'Mar',
        'Apr',
        'May',
        'Jun',
        'Jul',
        'Aug',
        'Sep',
        'Oct',
        'Nov',
        'Dec'
    ],
        crosshair: true
      },
      yAxis: {
        min: 0,
        title: {
          text: 'Rainfall (mm)'
        }
      },
      tooltip: {
        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
        '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
        footerFormat: '</table>',
        shared: true,
        useHTML: true
      },
      plotOptions: {
        column: {
          pointPadding: 0.2,
          borderWidth: 0
        }
      },
      series: [{
        name: 'Tokyo',
        data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]

      }, {
        name: 'New York',
        data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3]

      }, {
        name: 'London',
        data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2]

      }, {
        name: 'Berlin',
        data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1]

      }]
    });
  });
</script>

最佳答案

带有 ranat=server 的表单对 jquery 的服务器进行后调用,这会破坏你的屏幕。所以请尝试使用 jQuery 外部服务器标记来编写此代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="chart_test.aspx.cs" Inherits="WebUI_Commisions.CS3500.CS3510.chart_test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title></title>
  <script src="jquery-2.1.4.min.js" type="text/javascript"></script>
  <script src="https://code.highcharts.com/highcharts.js"></script>
  <script src="https://code.highcharts.com/modules/exporting.js"></script>
 </head>
 <body>

<form id="form1" runat="server">
  <div>

    <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
  </div>
</form>

<script type="text/javascript">
  $(function () {
    $('#container').highcharts({
      chart: {
        type: 'column'
      },
      title: {
        text: 'Monthly Average Rainfall'
      },
      subtitle: {
        text: 'Source: WorldClimate.com'
      },
      xAxis: {
        categories: [
        'Jan',
        'Feb',
        'Mar',
        'Apr',
        'May',
        'Jun',
        'Jul',
        'Aug',
        'Sep',
        'Oct',
        'Nov',
        'Dec'
    ],
        crosshair: true
      },
      yAxis: {
        min: 0,
        title: {
          text: 'Rainfall (mm)'
        }
      },
      tooltip: {
        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
        '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
        footerFormat: '</table>',
        shared: true,
        useHTML: true
      },
      plotOptions: {
        column: {
          pointPadding: 0.2,
          borderWidth: 0
        }
      },
      series: [{
        name: 'Tokyo',
        data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]

      }, {
        name: 'New York',
        data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3]

      }, {
        name: 'London',
        data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2]

      }, {
        name: 'Berlin',
        data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1]

      }]
    });
  });
</script>

关于jquery 在 runat=server 形式中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33956764/

相关文章:

javascript - 变量中的 jQuery (window).scrollTop()

javascript - 如何在javascript中向函数添加回调

javascript - 如何 DRY http 成功和错误函数?

c# - 无法启用此约束,因为并非所有值都具有相应的父值

asp.net - ASP.NET 2.0 中的 Gridview 列宽

jquery - 如何限制用户选择表单ajax自动完成建议

jquery - jQuery DataTable 中的复杂 header

c# - 从 React Native 访问 ASP.NET Core 2.1 Web API 时“无法验证 HTTPS 连接”

php - 为什么 (mono) asp.net 比 php 慢?

javascript - jqGrid - 在 IE 中产生 SCRIPT5007 错误,但在本地主机上工作