简体   繁体   English

清除TextBox.Text C#/ JS

[英]Clear TextBox.Text C#/JS

I have a problem to simply clear TextBox text ... I am using asp.net and bit of JS for project. 我有一个问题,只需清除TextBox文本...我正在使用asp.net和JS的项目。

But it seems Mozzila is to strong for my code and now it's bugging me. 但似乎Mozzila对我的代码很强大,现在它让我烦恼。

Idea is simple ... user can log in, and as always mozzila ask "Save credentials" which is fine 想法很简单......用户可以登录,并且一如既往mozzila问“保存凭据”,这很好

在此输入图像描述

But if user forget his password, select the link, I send him mail with URL, he comes back to new page which got text boxes 但是如果用户忘了他的密码,选择链接,我用URL发送邮件,他回到新页面,里面有文本框

在此输入图像描述

And for some reason Mozzila see my first TextBox as the one it "remembered the credentials" 出于某种原因,Mozzila将我的第一个TextBox看作是“记住凭据”的那个

在此输入图像描述

So i tried next things 所以我尝试了下一件事

<script type="text/javascript">
    $(document).ready(function () {

        document.getElementById("MainContent_txtNewPass1").value = "";
        document.getElementById("MainContent_txtNewPass2").value = "";

    });

</script>

And

protected void Page_Load(object sender, EventArgs e)
{
    txtNewPass1.Attributes["AUTOCOMPLETE"] = "off";
    txtNewPass2.Attributes["AUTOCOMPLETE"] = "off";

    txtNewPass1.Text = "";
    txtNewPass2.Text = "";
}

Which didn't worked, as I wouldn't be asking this question ... IDs of those asp:TextBoxes are different, I don't understand why is this happening or how to stop it from happening? 哪个没用,因为我不会问这个问题......那些asp的ID:TextBoxes是不同的,我不明白为什么会发生这种情况或如何阻止它发生?

EDIT 编辑

I am sure it's problem with Mozzila credential saving, as once I delete saved password, problem is gone. 我确定Mozzila凭证保存存在问题,因为一旦删除保存的密码,问题就消失了。 But at the end of a day, i just want to clear that TextBox.Text 但在一天结束时,我只想清除TextBox.Text

SOLUTION

If anyone gets a same problem ... I solved it but using 如果有人遇到同样的问题......我解决了它但使用了

window.onload = function () {
    document.getElementById("MainContent_txtNewPass1").value = "";
    document.getElementById("MainContent_txtNewPass2").value = "";
}

Instead $(document).ready(function () { 而是$(document).ready(function(){

Try this answer, the syntax is slightly different from what you have: https://stackoverflow.com/a/9686424/5013141 试试这个答案,语法略有不同: https//stackoverflow.com/a/9686424/5013141

Instead of 代替

txtNewPass1.Attributes["AUTOCOMPLETE"] = "off";

try this: 试试这个:

txtNewPass1.Attributes.Add("autocomplete", "off");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM