c#asp.net中的JavaScript函数按钮单击事件不起作用
我在一个asp.NETC#项目中。我想打印带有条形码的员工卡。因此,我在字符串变量callc#asp.net中的JavaScript函数按钮单击事件不起作用,javascript,c#,asp.net,Javascript,C#,Asp.net,我在一个asp.NETC#项目中。我想打印带有条形码的员工卡。因此,我在字符串变量callhtmlCon中编写了一个html标记,它将在客户端绑定一个DIV标记(获取所有员工并逐个循环打印)。 它很好用。但是在htmlCon变量中有java脚本函数,它不会在循环中运行 protected void btnGenarate_ClickEvent(object sender, EventArgs e) { ...... foreach (var item in empDetai
htmlCon
中编写了一个html标记,它将在客户端绑定一个DIV标记(获取所有员工并逐个循环打印)。
它很好用。但是在htmlCon
变量中有java脚本函数,它不会在循环中运行
protected void btnGenarate_ClickEvent(object sender, EventArgs e)
{
......
foreach (var item in empDetails)
{
htmlCon += ..........+
"<script>"+
"$(document).ready(function ()"+
"{ $('#barcode').JsBarcode('"+ item.EmployeeNo + "', { width: 1, height: 30 }); });"+
"</script>" +
"<img id='barcode' class='barcode'/>" +
"........................................"+
}
}
protectedvoid btnGenarate\u ClickEvent(对象发送方,事件参数e)
{
......
foreach(详细信息中的var项目)
{
htmlCon+=+
""+
“$(文档).ready(函数()”+
“{$('#barcode').JsBarcode('+item.EmployeeNo+“,{宽度:1,高度:30});”+
"" +
"" +
"........................................"+
}
}
此代码随条形码一起提供,它将在循环中打印第一轮。我想运行所有员工获取条形码。您正在生成许多具有相同ID的图像,您应该为每个循环迭代生成一个新ID。我还建议使用StringBuilder而不是一堆字符串连接:
protected void btnGenarate_ClickEvent(object sender, EventArgs e)
{
StringBuilder htmlCon = new StringBuilder();
for (int i = 0; i < empDetails.Count; i++)
{
htmlCon.AppendFormat("<script>$(document).ready(function () { $('#barcode{0}').JsBarcode('{1}', { width: 1, height: 30 }); });</script><img id='barcode{0}' class='barcode'/>",
i.ToString(), empDetails[i].EmployeeNo);
htmlCon.Append("........................................");
}
//To Use StringBuilder value
string html = htmlCon.ToString();
}
protectedvoid btnGenarate\u ClickEvent(对象发送方,事件参数e)
{
StringBuilder htmlCon=新的StringBuilder();
for(int i=0;i
谢谢。。我从中得到了答案$('#barcode{0}').JsBarcode('{1}',{宽度:1,高度:30});