获取asp标签值并放入javascript函数中
Get asp label value and put in javascript function
我有两个标签,我想获得值并存储在javascript函数中。我想把值放到饼图标签中。我只有一个,我不知道在另一个厂牌怎么做。请帮帮我。
这是我到目前为止写的。
* * Javascript * *
var pie = 0;
function changepie(val) {
pie = val;
}
var pie2 = 0;
function changepie2(val) {
pie2 = val;
}
前端 <asp:Label ID="Label1" runat="server" Text="Label" Visible="false"?</asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label" Visible="true"></asp:Label>
另一个饼状图加载javascript
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",
{
animationEnabled: true,
animationDuration: 1300,
backgroundColor: "transparent",
legend: {
verticalAlign: "bottom",
horizontalAlign: "center"
},
data: [
{
indexLabelFontSize: 10,
indexLabelFontWeight: "bold",
indexLabelFontFamily: "Helvetica",
indexLabelPlacement: "outside",
indexLabelLine: "none",
radius: "100%",
type: "pie",
toolTipContent: "{y} - <strong>#percent%</strong>",
dataPoints: [
{ y: pie, legendText: "",
label: pie + "%",
indexLabelLineColor: "#1dc7ea",
indexLabelFontColor: "#1dc7ea",
exploded: true,
indexLabelPadding: "5px"
},
{ y: pie2, legendText: "",
label: pie2,
indexLabelLineColor: "#FF4A55",
indexLabelFontColor: "#FF4A55"
}
]
}
]
});
chart.render();
}
这是我的后端
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Label1.Text = Session("percent").ToString.Replace("<span class>", "").Replace("</span>", "")
Label2.Text = Session("aaa").ToString
ClientScript.RegisterClientScriptBlock(Me.[GetType](), "Script", "changepie(" + Label1.Text + ");", True)
ClientScript.RegisterClientScriptBlock(Me.[GetType](), "Script", "changepie2(" + Label2.Text + ");", True)
End Sub
你需要确保
RegisterClientScriptBlock(Me.[GetType](), "Script", "changepie(" + Label1.Text + ");", True)
当被调用时,你只需要解析为int
使用Convert.ToInt32(Label1.Text)
在changepie函数中使用这个
var label1= 0;
function changepie(lbael1,label2) {
var chart = new CanvasJS.Chart("chartContainer",
{
animationEnabled: true,
animationDuration: 1300,
backgroundColor: "transparent",
legend: {
verticalAlign: "bottom",
horizontalAlign: "center"
},
data: [
{
indexLabelFontSize: 10,
indexLabelFontWeight: "bold",
indexLabelFontFamily: "Helvetica",
indexLabelPlacement: "outside",
indexLabelLine: "none",
radius: "100%",
type: "pie",
toolTipContent: "{y} - <strong>#percent%</strong>",
dataPoints: [
{ y: lbael1+", ", legendText: "",
label: pie + "%",
indexLabelLineColor: "#1dc7ea",
indexLabelFontColor: "#1dc7ea",
exploded: true,
indexLabelPadding: "5px"
},
{ y: label2, legendText: "",
label: pie2,
indexLabelLineColor: "#FF4A55",
indexLabelFontColor: "#FF4A55"
}
]
}
]
}
----------
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Label1.Text = Session("percent").ToString.Replace("<span class>", "").Replace("</span>", "")
Label2.Text = Session("aaa").ToString
ClientScript.RegisterClientScriptBlock(Me.[GetType](), "Script", "changepie(" + Label1.Text + "," + Label2.Text + ");", True)
End Sub
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 正在全局范围中查找JavaScript函数
- 如何将输入(type=text)从html表单传递到javascript函数
- 如何调用这个匿名 JavaScript 函数
- 通过Ajax将JavaScript函数传递给PHP文件
- 在javascript函数中设置全局变量
- 如何在执行此特定onclick事件时执行JavaScript函数
- 使用javascript函数在页面初始化后加载jquery
- javascript函数同步
- 如何将一个JavaScript函数回调为多个函数
- 在javascript函数中使用php变量
- 代码背后调用一个JavaScript函数的按钮点击-C#
- 将JavaScript函数与HTML分离
- 组合两个javascript函数
- 在 Java 中的 JavaScript 函数中插入 Wicket 值
- javascript函数内部的代码用逗号而不是分号分隔
- href属性内的javascript函数
- 使用html表单中的参数调用JavaScript函数
- 分析Javascript函数中的多个对象
- javascript函数的:和=之间的区别