0

文字列を生成する作業フォームがあり、ボタンをクリックすると、文字列がテキスト領域ボックス内に配置されます。

また、すべてのフィールドをリセットすると思われるリセットボタンもありますが、文字列のあるテキスト領域はリセットしません。

これが私のコードの一部です。

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:

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

});

クラスをリセットするすべての入力 ( clearit ) を指定し、リセット ボタンに ID: resetを取得しました。リセットしたくない唯一のフィールドは、別の ID を取得しました。

それは動作するはずですが、そうではありません..助けてください:)

4

1 に答える 1

0

このJavaScript関数を使用して、リセットしたくないIDの要素を除外します。入力を空白のままにするか、ドロップダウンを-1に等しくすることでリセットする方法を指定できます。

 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


        }


    }
于 2012-05-01T09:15:41.160 に答える