使用javascript在控件上设置属性 [英] Set attributes on a control using javascript

查看:69
本文介绍了使用javascript在控件上设置属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,



我正在使用Asp.Net创建一个应用程序。在这里,我想在运行时更改控件的属性。所以这里我使用链接按钮,并希望通过使用java脚本更改其属性。在这里我使用了这段代码,但它在这里不起作用。



 <   / script  >  
< script type = text / javascript >
function lnk1(){
var d =;
d = document.getElementById(<% lnk1 %> );
d.setAttribute(style,text-decoration:line-through);
}
< / script >







 <   asp:LinkBut​​ton     ID   =  lnk1    runat   =  server    OnClientClick   =  javascript:lnk1();   > <   / asp:LinkBut​​ton  >  / <跨越ss =code-keyword><   asp:LinkBut​​ton   
< span class =code-attribute>
< span class =code-attribute> ID = lnk2 runat = 服务器 > < / asp :LinkBut​​ton >

解决方案

你不能使用< %%>在javascript中这是一个ASP标签。



替换

 d =  document  .getElementById( <%lnk1%>); 









 d =  document  .getElementById('  lnk1') ; 


Dear sir,

I am create an application using Asp.Net. Here I want to change attribute of my controls at run time. so here I am using link button and want to change its attribute by using java script. Here I used this code but it does not work here.

</script>
             <script type="text/javascript">
                 function lnk1() {
                     var d = "";
              d = document.getElementById("<%lnk1 %>");
             d.setAttribute("style", "text-decoration:line-through");
            }
   </script>




<asp:LinkButton ID="lnk1" runat="server" OnClientClick="javascript:lnk1();" >Yes</asp:LinkButton>/<asp:LinkButton

                   ID="lnk2" runat="server">No</asp:LinkButton>

解决方案

You can't use <% %> in javascript this is an ASP tag.

Replace

d = document.getElementById("<%lnk1 %>");



With

d = document.getElementById('lnk1');


这篇关于使用javascript在控件上设置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆