简体   繁体   English

启用或禁用基于TextBox的按钮。文本文本更改

[英]Enable or Disable Button Based On TextBox.Text Text Changes

I am creating a web application for my company. 我正在为我的公司创建一个Web应用程序。 My application has a button and a textbox. 我的应用程序有一个按钮和一个文本框。

What I want to do is entering some value into the textbox and then when i click the button the application will process the value based on the input in the textbox. 我想做的是在文本框中输入一些值,然后当我单击按钮时,应用程序将根据文本框中的输入处理该值。

Now here is the tricky part. 现在是棘手的部分。

After the button is clicked once and the text in textbox remains, the button shall disappear. 单击一次按钮后,文本框中的文本仍然保留,该按钮应消失。

However if there is modification in the textbox.text, the button shall reappear. 但是,如果textbox.text中有修改,该按钮将重新出现。

But if the textbox.tex somehow return to original value, the button shall disappear again. 但是,如果textbox.tex以某种方式返回到原始值,则该按钮将再次消失。

Please its quite urgent, I have tried my best to do it already, yet so far unsuccessful. 请它非常紧急,我已经尽力了,但是到目前为止还没有成功。 I also did a lot of research in Google, but so far none of my findings suit my case. 我还在Google上进行了很多研究,但到目前为止,我的发现均不适合我的情况。

Your help is appreciated. 感谢您的帮助。

You got it here http://jsfiddle.net/ywe9G/ 您在这里找到它http://jsfiddle.net/ywe9G/

var ori = '';
$(document).ready(function(){
    $('button').hide();
    $('input').keyup(function(){
        if($(this).val() != ori){
                $('button').show();
        }else{
            $('button').hide();
        }
    });
    $('button').click(function(){
        ori  = $('input').val();
        $(this).hide();
    });
});
    private string oldTextboxValue = "";
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        if (textBox1.Text != oldTextboxValue)
        {
            button1.Visible = true;
        }
        else
        {
            button1.Visible = false;
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        oldTextboxValue = textBox1.Text;
        button1.Visible = false;
    }

to disable button you can do this- 禁用按钮,您可以执行以下操作-

var oldvalue="";
$('#buttonid').click(function(){
//your code
oldvalue = $("#textBox").text();
this.hide();
}

$("#textBoxId").keypress(function(){
if(this.value!=oldvalue){
this.show();
}
}

Demo here 在这里演示

HTML 的HTML

<textarea id='mytext' rows='4' cols='20'></textarea>
<br>
<input type="button" id='my_button' value="click">
<input type="hidden" id="my_hidden">

jQuery jQuery的

var clicked=false;
jQuery(document).ready(function() {
    $("#my_button").click(function(){
        $("#my_hidden").val($("#mytext").val());
        $(this).hide();
        clicked=true;
    });

    $("#mytext").keyup(function(){
       if(clicked==true && $(this).val()==$("#my_hidden").val()) {
           $("#my_button").hide();
       }else if(clicked==true){
           $("#my_button").show();
       }
    });

});

You can similarly enable/disable button instead of show/hide 您可以类似地启用/禁用按钮,而不是显示/隐藏

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

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