Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 检测文本输入并清除其他文本框_Jquery - Fatal编程技术网

Jquery 检测文本输入并清除其他文本框

Jquery 检测文本输入并清除其他文本框,jquery,Jquery,我有一个名为startDateTextBox的文本框。当用户在此框中键入值时,我希望清除其他文本框 这是我的密码: $(document).ready(function ($){ $('#startDateTextBox').on("textchange",function(){ $("#startExciseNumberTextBox").val(''); $("#endExciseNumberTextBox").val('');

我有一个名为startDateTextBox的文本框。当用户在此框中键入值时,我希望清除其他文本框

这是我的密码:

$(document).ready(function ($){
       $('#startDateTextBox').on("textchange",function(){ 
           $("#startExciseNumberTextBox").val('');
           $("#endExciseNumberTextBox").val('');
       });
 });
$(函数(){
$('#startDateTextBox')。打开(“更改”,函数(){
$(“输入”).not(this.val(“”);
});
});

尝试使用JQuery实现:

$("input").change(function(){
    alert("The text has been changed.");
});
或者,扩展您自己的代码:

$(document).ready(function () {
    $('#startDateTextBox').on('change', function() {
        //do stuff
    });
});

我认为没有
changetext
事件,只有和事件

$('startDateTextBox')。打开('input',clearInputs);
功能输入(e){
$(':text').not(this.val('');
}







要清除其他文本框很简单,只需监听按键、向上键、粘贴或向下键事件,并确保startDateTextBox不为空

注意:如果在其他文本框上使用ID,代码将只在第一个ID文本框上工作,因此用户类属性而不是ID可以避免这种情况发生

使用以下代码:

$(document).ready(function(){
$("#startDateTextBox").on('keypress keyup keydown paste', function(){

if($(this).val().trim() != ""){

   //clear the other textboxes here 

   $("#startExciseNumberTextBox").val('');
  $("#endExciseNumberTextBox").val('');

}
})

})

使用
keypress
代替
textchange
input
代替
textchange
其他两个特定输入,还是文档中的所有输入?