简体   繁体   English

jQuery附加BulletList C#控件的问题

[英]Jquery append issue with BulletList C# control

var eq = Cost/Sales;
var delimiters = "+-*/()";
var result = new Array();
var chunk = "";
var regex =  /[()*/+-]|[A-Z a-z]+|\d+/g;
var parts = eq.match(regex);
for (var i = 0; i < parts.length; i++)
{
      $("#ctl00_ContentPlaceHolder1_Destination").append('<li>'+parts[i]+'</li>');
       alert('<li>'+parts[i]+'</li>');     
}

<CTExtension:EmptyBulletedList ID="Destination" runat="Server" class="connectedSortable"></CTExtension:EmptyBulletedList>

I have following code in my javascript to break the value in to array. 我的JavaScript中有以下代码,可将值拆分为数组。 Now I want to append it one by one into destination id-control which is bullet list from my C#. 现在,我想将其一个接一个地附加到目标ID控件中,该ID是我的C#中的项目符号列表。 But the above code does not append the values. 但是上面的代码没有附加值。 Please help! 请帮忙! and it creates the ul tag when i run the page 它在我运行页面时创建ul标签

At runtime, is the value of your #ctl00 still the same? 在运行时,您的#ctl00的值是否仍然相同? That looks like a placeholder in ASP.NET meaning the actual value could change at runtime. 看起来像ASP.NET中的占位符,意味着实际值可能会在运行时更改。 Also, when you say it is not appending the values, what is it doing instead. 另外,当您说它不附加值时,它在做什么。 Are you getting any javascript errors in the console? 您在控制台中遇到任何JavaScript错误吗? Are you getting the alert? 您收到警报了吗? Do a View Source on the page after it loads and make sure the ID you are passing the JQuery selector is correct. 加载后在页面上执行“查看源代码”,并确保您传递的JQuery选择器ID是正确的。

I would assume the ControlID is changing, and therefore your selector is no longer valid. 我认为ControlID正在更改,因此您的选择器不再有效。

See my Fiddle below, it's working, start from a working solution and make changes until it breaks, then you will know where it's going wrong. 请参阅下面的我的小提琴,它正在工作,从一个有效的解决方案开始,进行更改直到崩溃,然后您将知道它出了什么问题。

http://jsfiddle.net/zWXCN/ http://jsfiddle.net/zWXCN/

for (var i = 0; i < 20; i++)
            {
                  $("#test").append('<li>'+i+'</li>');
                   //alert('<li>'+i+'</li>');     
            }

Directly referencing your element via the automatically generated ASP.NET ID can cause problems. 通过自动生成的ASP.NET ID直接引用您的元素可能会导致问题。 Can you check if that ID is still correct (using developer tools in the browser)? 您可以检查该ID是否仍然正确(使用浏览器中的开发人员工具)吗?

Instead you should reference your control like: 相反,您应该像这样引用控件:

$('#<%= Destination.ClientID %>')

This means that regardless of the structure of your page, or the implementation of the ClientID, you will always be referencing the correct control. 这意味着无论页面结构或ClientID的实现如何,您将始终引用正确的控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM