Javascript 在字段中输入文本时需要启用按钮。
我需要在文本框中键入文本时启用按钮。我做错了什么 代码:Javascript 在字段中输入文本时需要启用按钮。,javascript,html,Javascript,Html,我需要在文本框中键入文本时启用按钮。我做错了什么 代码: 函数IsEmpty(){ if(input1.value!=null){ sendbutton.enabled==true; } } IsEmpty(); 发送 您可能想要sendbutton.enabled=true,带有单个=。您编写的内容检查它们是否相等(false,大概),然后对结果不做任何处理。将您的JavaScript更改为: var input1 = document.getElementById('input1'),
函数IsEmpty(){
if(input1.value!=null){
sendbutton.enabled==true;
}
}
IsEmpty();
发送
您可能想要sendbutton.enabled=true代码>,带有单个=
。您编写的内容检查它们是否相等(false
,大概),然后对结果不做任何处理。将您的JavaScript更改为:
var input1 = document.getElementById('input1'),
sendbutton = document.getElementById('sendbutton');
function IsEmpty(){
if (input1.value){
sendbutton.removeAttribute('disabled');
} else {
sendbutton.addAttribute('disabled', '');
}
}
input1.onkeyup = IsEmpty;
和HTML:
<input class="draft" id="input1" type="text"/>
<button class="send" id="sendbutton" disabled>Send</button>
发送
要在DOM中修改元素,您需要使用纯Javascript的功能,比如getElementById函数,或者任何其他Javascript框架
document.getElementById('sendbutton'))
然后引用该属性并对其进行更改
您还可以使用JQuery,它将帮助您进行堆处理。我是说,使用选择器
希望这会有所帮助,您需要为输入元素分配一个id。
You need to assign an id to your input element.
<input class="draft" name="input1" id='input1' type="text"/>
and in your javascript access it like this:
if(document.getElementById('input1').value != null || document.getElementById('input1').value!='undefined'){
document.getElementById('sendbutton').disabled=false;
}
在javascript中,您可以这样访问它:
if(document.getElementById('input1').value!=null | | document.getElementById('input1').value!=undefined')){
document.getElementById('sendbutton')。disabled=false;
}
您需要在其中添加一些javascript处理事件。
You need to assign an id to your input element.
<input class="draft" name="input1" id='input1' type="text"/>
and in your javascript access it like this:
if(document.getElementById('input1').value != null || document.getElementById('input1').value!='undefined'){
document.getElementById('sendbutton').disabled=false;
}