本文介绍了从服务器端调用客户端JavaScript function()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
如何从服务器端调用客户端javascript函数.
请帮忙.
我正在等待....我想从(Page_Load(object sender,EventArgs e)的服务器端调用dTime().
示例:

Dear All,
How to call a client side javascript function from server side.
Please help.
I am waiting.. ..I want to call dTime() from Server side on (Page_Load(object sender, EventArgs e).
Example:

<script language="javascript" type="text/javascript">
    function dTime() {

        var d = new Date();

        var h = d.getHours();

        var m = d.getMinutes();

        var s = d.getSeconds();



        //add a zero in front of numbers < 10



        m = checkTime(m);



        s = checkTime(s);





        document.getElementById('txt').innerHTML = h + ":" + m + ":" + s;

        t = setTimeout('dTime()', 500);

    }



    function checkTime(i) {



        if (i < 10) {



            i = "0" + i;



        }

        return i;

    }



</script>





<tr>
        <div id="txt">
         </div>

       <td>

         <form action="#">

        </form>

    </td>
    </tr>





谢谢,
Emon Mahmud





Thanks,
Emon Mahmud

推荐答案

Page.RegisterStartupScript("page", "<script language='javascript'>dTime()</script>");



代替page.RegisterStartupScript,您也可以使用ClientScript.RegisterClientScriptBlock

如果您在aspx页面中使用更新面板,请使用

ScriptManager.RegisterClientScriptBlock
有关scriptmanager的信息,请参见 [ ^ ]



in place of page.RegisterStartupScript you can also use ClientScript.RegisterClientScriptBlock

if you are using update panel in your aspx page then use

ScriptManager.RegisterClientScriptBlock
for scriptmanager see this[^]



<body onload="dTime()">



通过使用此功能,您还可以从客户端也在pageload上激活它

最好的



by using this you can activate it on pageload from client side also

All the Best


这篇关于从服务器端调用客户端JavaScript function()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 13:37