html - Asp .Net 客户端动态文本

标签 html asp.net

我正在学习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。

enter image description here

最佳答案

看看这个 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/

相关文章:

c# - FileHelperEngine 构造函数 - InvalidcastException

javascript - 获取 DayPilot Scheduler 的 DataResourceField 值

asp.net - azure 网站不会从基本网站缩小,因为报告的大小不正确

html - 如何停止 IE 滚动*隐藏*溢出的内容

html - 我可以在行内使用 Bootstrap 容器类吗?

Javascript 计数器函数 onload 不起作用

html - IE9 背景图片 1 白色 px :(

html - 单击单选按钮标签而不选择按钮本身

asp.net - Linq 更新查询生成 Where 0 = 1?

c# - DisplayAttribute 名称属性在 Silverlight 中不起作用