我想刪除輸入字段值,同時點擊button.How我可以做到這一點。刪除輸入字段值onclick
例如
<input type="text" name="text"> /***************IF value =Akram ************/
<input type="button">
我想刪除輸入字段值,同時點擊button.How我可以做到這一點。刪除輸入字段值onclick
例如
<input type="text" name="text"> /***************IF value =Akram ************/
<input type="button">
HTML:
<input type="text" name="text" value="Akram">
<input type="text" name="text" value="something else">
<input type="submit" value="button" id="btn" />
的jQuery:
$('#btn').click(function(){
$('input').each(function(){
if ($(this).val() == "Akram")
$(this).val('');
});
});
DEMO:
試試這個:
$(function(){
$('input[type=button]').click(function(){
if($('input[type=text]').val() == 'something')
$('input[type=text]').val('');
});
});
<input type="text" name="text" id="input" />
<input type="button" onclick="if($('#input').val() == 'Akram'){ $('#input').val(''); }" />
您可以使用HTML唯一的解決辦法,當你把你輸入元素的形式
<form>
<input type="text" name="text" />
<input type="reset" />
</form>
這裏是一個JavaScript版本
<input id="text" type="text" name="text" />
<input id="button" type="button" />
var text = document.getElementById('text');
var button = document.getElementById('button');
button.onclick = function() {
text.value = '';
}
。輸入將以一流的選擇。您需要#輸入通過ID – Hazaart
選擇正確。固定。 – user202172
你有兩個選擇器 – Hazaart