Javascript停止使用母版页 [英] Javascript stopped working with master page

查看:91
本文介绍了Javascript停止使用母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用母版页开发应用程序时,我会在内容页中输入一些验证信息.

它可以正常工作,但是一段时间后它将停止工作.

这是我的javascipt函数,很简单,但是它停止了工作.

When I developed my application with masterpage I enter some validation in content page.

It will work fine, but after some time it will stop working.

This is my javascipt function it is simple but it stopped working.

function reset()
    {
    document.getElementById("<%=txt_fh_name.ClientID%>").value="";
    document.getElementById("<%=txt_mobile.ClientID%>").value="";
    document.getElementById("<%=txt_add.ClientID%>").value="";
    document.getElementById("<%=txt_email.ClientID%>").value="";
    }




谁能告诉我如何解决这个问题或为什么会这样?
谢谢.




Can anybody tell me how to solve this problem or why it is doing like this?
Thanks.

推荐答案

当我们使用母版页并将内容放入ContentPlace Holder时,控件的ID将更改,您可以在源代码中看到您的文本框ID将以"ct100"开头,因此有时在使用
时会出现问题
document.getElementById(<%= txt_fh_name.ClientID%>").value =";
将无法获取ID

最简单的方法是从源代码中复制呈现的ID,并将其放入
getElementById方法,它将正常工作.
When We are Using Master Pages and Put our content in ContentPlace Holder then the ID of the control will be changed you can see in the source code your textbox ID will start with "ct100" so sometime there will be a issue that while using

document.getElementById("<%=txt_fh_name.ClientID%>").value="";
will not able to get ID

The easiest way is just copy the rendered ID from source code and put in the
getElementById method it will work properly.


检查您的html源代码并检查控件的生成ID.是否相同...

或尝试使用document.getElementByName代替使用document.getElementByID

让我知道会发生什么..?

让它回答是否可行...

谢谢
灰烬
Check your html source code and check the generated id''s of the controls..are they same...

or try document.getElementByName instead of using document.getElementByID

let me know what happens..?

make it answer if it works...

Thanks
Ashish


这篇关于Javascript停止使用母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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