У меня была эта проблема сама. Ответ Майка близок, но, на мой взгляд, не идеален: он очищает элементы, даже если атрибут value
может захотеть установить его.
На странице загрузки я делаю следующее. Он использует только немного jQuery.
// Reset input elements to their HTML attributes (value, checked)
$("input").each(function(){
// match checkbox and radiobox checked state with the attribute
if((this.getAttribute('checked')==null) == this.checked)
this.checked = !this.checked;
// reset value for anything else
else this.value = this.getAttribute('value')||'';
});
// Select the option that is set by the HTML attribute (selected)
$("select").each(function(){
var opts = $("option",this), selected = 0;
for(var i=0; i<opts.length; i++)
if(opts[i].getAttribute('selected')!==null)
selected = i;
this.selectedIndex = selected||0;
});
Нет jQuery?
Используйте document.getElementsByTagName
, чтобы выбрать input
s и select
s, затем выполните итерацию по ним и замените this
на повторяющийся элемент.
Выберите опции с помощью .getElementsByTagName('option')
.