重置按钮以指定字段 [英] Reset button for specific fields

查看:72
本文介绍了重置按钮以指定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成一个字符串的工作表单,通过点击一个按钮它将字符串放在一个文本区框中。

I have a working form that generates a string, and by clicking on a button it places the string inside a text area box.

我也有一个重置按钮假设重置所有字段而不是字符串的文本区域。

I also have a reset button that suppose to reset all fields but not the text area with the strings.

这是我的一些代码。

HTML:

HTML:

<form>

<!--some more code and inputs-->

</tbody> </table> </p> <p> <input value="Generate URL" onclick="createURL1();" type="button">


<input name="result" size="70" class="clearit" type="text" ></input>
<input type="button" value="Add The Link" onClick="addtext();"></p>
<textarea id="t5" style="width:600px;" name="outputtext" ></textarea><br><br>


 </p>  </td> </tr> </tbody> </table>

<input  type="reset" value="Clear" id="reset" ></input>

JavaScript:

JavaScript:

$(document).ready(function(){
    $('#reset').on('click',function(e){
        e.preventDefault();
        $('.clearit').val("");
    });

});

我给出了所有要重置类的输入( clearit )并且重置按钮有一个ID: reset 。我不希望被重置的唯一字段有一个不同的ID。

I gave all the inputs that I want to reset a class (clearit) and the reset button got an ID: reset. The only field I didn't want to be reset got a different id.

它应该工作,而不是..请帮助:)

it's supposed to work and its not.. Please Help :)

推荐答案

使用此javascript函数并排除带有您不想重置的ID的元素,并且您可以指定通过左输入空白或下拉-1
,它适用于IE和fire fox tesed

use this javascript function and exclude the element with id you dont want to reset and you can specify the way to reset either by left input blank or dropdown equal -1 and it works on IE and fire fox tesed

 function resetLabels()
    {
        //mainForm is the name of form
        var cells = document.mainForm.elements;
        for (var i= 0; i < cells.length; i++) {
             if(cells[i].name !='txtName')//for example to not reset by name 
            cells[i].value='';

   //    cells[i].className = '';
   //    cells[i].style.color = 'black';
   // or cells[i].value='-1' for drop down
   // or cells[i].name= '';  name and id to compare and exclude specific elements
   // or cells[i].id= '';    
   //and i suggest to name like txt... and ddl...to                                  
   //know the type by name and id or just check the type
   //of element by using  cells[i].type


        }


    }

这篇关于重置按钮以指定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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