使用javascript取消隐藏和隐藏表单中的某些元素
Unhide and hide some element within the form using javascript
大家好,我正在尝试隐藏和取消隐藏表单中的一些元素,例如,当单击文本区域时,必须启用发布按钮。问题是我不擅长javascript,所以我需要在这方面的帮助/指导,即使是教程的链接也可以。
这是一个包含HTML、JavaScript和jQuery的完整示例。您基本上有一个文本区域和一个隐藏(和禁用)按钮。JavaScript代码只需在文本区域添加一个点击事件,并启用表单中的按钮
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$('textarea#some-textarea-id').click(function(){
$('button#some-button-id').show().removeAttr('disabled');
});
});
</script>
</head>
<body>
<form>
<textarea id="some-text-area-id"></textarea>
<button id="some-button-id" style="display: none" disabled>CLICK ME</button>
</form>
</body>
</html>
资源:
http://www.w3schools.com/jquery/
http://www.tutorialspoint.com/jquery/
https://learn.jquery.com/about-jquery/how-jquery-works/
这个问题有点模糊,但下面的代码可能会帮助您弄清楚:
$('#your_textarea_id').on('click', function(){ // add an event listener to your tag/textarea
$('#post_button_id').removeAttr('disabled'); // removes the disable of your post button
})
如果您想隐藏/显示,只需将removeAttr("已禁用")替换为toggle(),依此类推
Refer to the code below
$(document).ready(function(){
$('textarea').on('click', function(){
$('#button-id').attr('disabled', false);
});
});
where '#button-id' is the id of button you want to disable on the click event of textarea.
相关文章:
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- JavaScript-在手机上不工作的情况下,在外部单击时隐藏元素
- 随时隐藏元素
- 根据特定条件使用ng显示/ng隐藏来显示/隐藏元素
- 隐藏元素直到加载完成(ng斗篷不是我需要的)
- 在具有类的元素中隐藏元素
- javascript()onclick隐藏元素-dos'我不在firefox工作
- JQueryHide()在按钮中使用元素时不会隐藏元素
- 使用Javascript取消隐藏元素
- 如果鼠标离开父对象,则隐藏元素
- 如何在jquery ajax成功html响应中找到输入隐藏元素
- 基于事件在循环中隐藏元素
- 渐进式增强-不使用CSS隐藏元素
- 隐藏元素后更新滚动条
- jQuery没有隐藏元素
- jQuery隐藏元素在使用CSS显示时保持隐藏状态
- 如何使用javascript在区域外单击时隐藏元素
- 如何在加载网页时隐藏元素
- JS:隐藏元素上的事件侦听器
- HTML 显示/隐藏元素 JS 不起作用