我正在尝试在ASP.NET服务器端代码中读取在单击事件时由Javascript添加的类,但它仍然只显示那些在初始化时由服务器添加的类。
这是HTML元素的快照。

下面是ASP.NET代码正在读取的内容。

我甚至试着像读string css = imgThumbnail.Attrinutes["class"].ToString();一样读它,但它仍然返回相同的结果。
我想在后面的代码中阅读“border-10”类。
发布于 2019-07-27 17:34:40
您必须使用HiddenFileds或隐藏的TextBox。
发布于 2019-07-27 19:22:44
是的,就像马赫迪说的,你需要使用隐藏字段。因此,创建隐藏字段,例如:
<input type="hidden" id="Yourstylesheetinfo" asp-for="Yoursheetinfo" />然后,通过JS为该字段设置值:
var YourElement = document.getElementById(`YourElementsID`);
var style = window.getComputedStyle(YourElement);
//if you looking for border
var property = style.getPropertyValue('border');
//Lastly set value to hidden input
document.getElementById(`Yourstylesheetinfo`).value = property;
//maybe you'll need to use .toString() on property ? on line above this..也许是这样的。
https://stackoverflow.com/questions/57230812
复制相似问题