清除文本框 脚本不起作用
Clear textboxes Script not working
我有这个form
和这个Script
,但Script
不起作用。我像一个月前一样使用它,它有效,但现在不起作用。
<form method="post">
<input type="hidden" name="depName" value="<?php echo $_GET['var'];?>">
<input type="hidden" name="personStat" value="Espera">
<div class="input1">FirstName :<input type="text" name="fname" class="in1" value="<?php echo $nombre;?>"> <span class="error1">* <?php echo $nombreErr;?></span> </div>
<div class="input2">LastName :<input type="text" name="lname" class="in2" value="<?php echo $apellido;?>"> <span class="error2">* <?php echo $apellidoErr;?></span> </div>
<div class="input3">2LastName :<input type="text" name="Slname" class="in3" value="<?php echo $segundoAppellido; ?>"> <span class="error1"><?php echo $segundoAppellidoErr; ?></span> </div>
<div class="input4">Student Id :<input type="text" name="studentId" class="in4" value="<?php echo $idEstudiante;?>"> <span class="error2"><?php echo $idEstudianteErr; ?></span> </div>
<input class="buttonClr" type="button" value="Clear">
</form>
脚本
<script> //Funtion that works on buttonClr click
$(".buttonClr").live('click',function(){
$(this).parents('form').find('input[type="text"]').val(''); //Clear all textboxes
$('Select').val(''); //Clear the multiple select
});
</script>
我猜你已经将jquery更新到1.7或更高版本,所以live()
不再有效。这是jQuery文档中的解释
从jQuery 1.7开始,.live()方法已被弃用。使用 .on() 附加事件处理程序。使用旧版本的 jQuery 的用户应优先使用 .delegate() 而不是 .live()。
更改脚本,如下所示
<script> //Funtion that works on buttonClr click
$(".buttonClr").on('click',function(){
$(this).parents('form').find('input[type="text"]').val(''); //Clear all textboxes
$('Select').val(''); //Clear the multiple select
});
</script>
工作演示:http://jsfiddle.net/16nu4aom/
尝试使用此脚本来清除输入字段:
$(".buttonClr").bind('click',function(){
$(this).parents('form').find('input[type="text"]').val(''); //Clear all textboxes
$('Select').val(''); //Clear the multiple select
});
我建议您使用重置按钮而不是JS
。例:
<form method="post">
<input type="hidden" name="depName" value="<?php echo $_GET['var'];?>">
<input type="hidden" name="personStat" value="Espera">
<div class="input1">FirstName :<input type="text" name="fname" class="in1" value="<?php echo $nombre;?>"> <span class="error1">* <?php echo $nombreErr;?></span> </div>
<div class="input2">LastName :<input type="text" name="lname" class="in2" value="<?php echo $apellido;?>"> <span class="error2">* <?php echo $apellidoErr;?></span> </div>
<div class="input3">2LastName :<input type="text" name="Slname" class="in3" value="<?php echo $segundoAppellido; ?>"> <span class="error1"><?php echo $segundoAppellidoErr; ?></span> </div>
<div class="input4">Student Id :<input type="text" name="studentId" class="in4" value="<?php echo $idEstudiante;?>"> <span class="error2"><?php echo $idEstudianteErr; ?></span> </div>
<input class="buttonClr" type="reset" value="Clear">
<!---^^^^^^^-->
</form>
如果只想重置所有表单字段,则只需添加重置按钮即可。这是一键重置按钮的最简单方法。
<input type="reset" value="Reset"/>
相关文章:
- 当有许多形式时,Fancybox脚本不起作用
- Aureliaview中的脚本不起作用
- JQuery脚本在IE中不起作用
- 淡入淡出脚本不起作用
- 未捕获的类型错误:无法设置属性'innerHTML'如果为null,则将脚本移动到正文不会;不起作用
- jQuery脚本在googlechrome中不起作用
- 替换字符串的脚本;在某些网站上不起作用
- 从jquery对话框恢复原始数据,脚本不起作用
- java脚本中的谷歌地图在第二次点击时不起作用
- 我的脚本不起作用
- JavaScript onScroll在谷歌应用程序脚本web应用程序中不起作用
- 为什么锚在此脚本中不起作用
- getRange(单元格)在谷歌应用程序脚本中不起作用
- 脚本在我的引导模式中不起作用
- 用于wooccommerce的简单JQuery脚本不起作用
- 对照数组脚本检查文本框中的值不起作用
- 脚本在IE 9中不起作用
- 如果视图中没有Jquery脚本引用,Unobtrusive Javascript Validation是不起作用的
- Codeigniter :通过 AJAX 调用 php 脚本时路由不起作用
- 谷歌转化不起作用 - 脚本无法加载