テキストボックスの値が(例として)「Hello」の場合、divを表示する必要があります。もちろん、「Hello」は必要ありませんが、これは単なる例です。したがって、JavaScript を使用すれば、これを行うことができると思いますが、JavaScript があまり得意ではないので、助けが必要です。
2 に答える
2
これがいつ発生するかを正確に明確にしないと、具体的な回答を提供できませんが、ガイダンスとしては次の情報で十分です。
var stringToMatch = 'hello',
input = document.getElementById('inputElementId'),
div = document.getElementById('divId');
input.onkeyup = function(e){
if (this.value == stringToMatch){
div.style.display = 'block';
}
else {
div.style.display = 'none';
}
};
大文字と小文字を区別しないマッチングを希望する場合:
var stringToMatch = 'hello',
input = document.getElementById('inputElementId'),
div = document.getElementById('divId');
input.onkeyup = function(e){
if (this.value.toLowerCase() == stringToMatch.toLowerCase()){
div.style.display = 'block';
}
else {
div.style.display = 'none';
}
};
参考文献:
于 2012-06-24T19:46:03.443 に答える
1
多分これはあなたが探しているものです。
<div id="div2show">Show me</div>
<textarea id="text"></textarea>
input = document.getElementById('text'), div = document.getElementById('div2show');
input.onkeyup = function (e) {
if (this.value == 'hello') {
div.style.display = 'block';
}
};
于 2012-06-24T19:53:38.357 に答える