<input type="text"/> <button>Go</button>
<div id="example">
</div>
如果 input
包含 5 个字符,而 button
为单击,.append
如果没有单击“其他”?
最佳答案
var example = $('#example'); //get example div
var input = $('input').get(0); //get first input in the set of inputs
$('button').click(function(){ //bind click handlers to (any) button
var value = input.value; //get the (first) input's value
if(value.length === 5){ //check the value
example.append('Blah');
} else {
example.append('Other');
}
});
关于javascript - 如果输入框包含一定数量的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10221755/