[英]Executing client-side script on link click
I need my web page to open a window and enable a disabled button when a link or a button is clicked. 我需要我的网页打开一个窗口,并在单击链接或按钮时启用禁用的按钮。 From what I've read on other posts on here, if I try and open a new window in Page_load most browsers will assume it's a pop-up and block it so I've been trying to do it client side with JS. 从我在这里的其他文章中所读到的内容中,如果我尝试在Page_load中打开一个新窗口,则大多数浏览器会假定它是一个弹出窗口并阻止它,因此我一直在尝试使用JS在客户端进行操作。
Currently, I'm trying it with a link declared like so: 目前,我正在尝试使用这样声明的链接进行尝试:
Please click <a href="javascript:OpenDoc()">here</a> to open the document.
This calls the following JS: 这将调用以下JS:
function OpenDoc()
{
<%= btnSubmit.ClientID %>.Visible = true;
Window.Open('GetDocument.aspx')
}
Unfortunately, instead of rending the JS as "btnSubmit.Visible = true" it comes out as "MainContent_btnSubmit.Visible = true" which doesn't work. 不幸的是,它不是将JS借为“ btnSubmit.Visible = true”,而是显示为“ MainContent_btnSubmit.Visible = true”,这是行不通的。
Assuming this is the best way of doing what I want, where am I going wrong? 假设这是做我想要的事情的最好方法,我在哪里做错了?
You can't change visibility property through javascript but you can use the following code instead of it : 您无法通过javascript更改可见性属性,但可以使用以下代码代替它:
var control = document.getElementById('<%=btnSubmit.ClientID %>');
control.disabled = true;
In this case the button will be disabled and if you need to hide button not disableing it then use the following code : 在这种情况下,该按钮将被禁用,如果您需要隐藏按钮而不禁用它,请使用以下代码:
var control = document.getElementById('<%=btnSubmit.ClientID %>');
control.style.display= "none";
Hope this is helpfull based on my understanding to your problem 希望对我的问题有帮助,对我有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.