関数を使用して、コンテナー内のフォーム フィールドの入力値をクリアします。
function clear_form_elements(ele) {
$(ele).find(':input').each(function() {
switch(this.type) {
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
$(this).val('');
break;
case 'checkbox':
case 'radio':
this.checked = false;
}
});}
これにより、div、フィールドセットなど (ele として定義) 内の一連の入力フィールドが完全にクリアされます。今、私は
$(this).val('');
と
if(this.id = "town") {this.val('town');}
if(this.id = "country") {this.val('country');}
入力要素を異なる ID に置き換えますが、要素の ID が異なっていても、各入力フィールドに返される値は常に「国」です。
私は何を間違っていますか?