我正在学习Asp.Net,写完一个母版页后,我无法让它在客户端上运行(实际看到动画)。线程等待操作是在发布网页之前在服务器上完成的,因此动画不是动态的。它仅显示页面的最终状态。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body bgcolor="red">
<center>
<h2>Hello w3schools!</h2>
<h4 id="aa">qq</h4>
<h3>
<p><%
for (int i = 0; i < 30; i++)
{
System.Threading.Thread.Sleep(25);
int txtLeft = 300 + (int)(100*Math.Sin(i));
int txtTop = 300+(int)(100*Math.Cos(i));
string theText = "Hello there!";
Response.Write("<div style=\"position:absolute; left: "+ txtLeft + "px; top:" + txtTop + "px; \">" + theText +"</div>");
}
%></p>
</h3>
</center>
</body>
</html>
我试过了
runat="client" (near the "p" letter which is in brackets)
但失败了:
Runat 必须具有值 Server。
最佳答案
看看这个 jsFiddle:
$(Start);
function Start() {
var txtLeft, txtTop, theText, theHTML;
theText = "Hello there!";
for (var i = 0; i < 30; i++) {
txtLeft = 300 + (100 * Math.sin(i));
txtTop = 300 + (100 * Math.cos(i));
theHTML = '<div style="position:absolute; left: ' + txtLeft + 'px; top:' + txtTop + 'px;">' + theText + '</div>';
$('#Demo').append(theHTML);
}
}
基本上,不需要服务器端编程来生成您想要的输出;使用 asp.net 进行服务器工作。您可以做的就是将此脚本与 jquery 引用一起添加到 script
标记中的页面,然后就完成了。
关于html - Asp .Net 客户端动态文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21968641/