如果您对javascript-通过remove属性启用和禁用按钮和jsremovelistener感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解javascript-通过remove属性启用和
如果您对javascript-通过remove属性启用和禁用按钮和js removelistener感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解javascript-通过remove属性启用和禁用按钮的各种细节,并对js removelistener进行深入的分析,此外还有关于
- javascript-通过remove属性启用和禁用按钮(js removelistener)
节点删除(empty()与remove()方法) - asp.net – 如何根据用户角色启用和禁用按钮?
- css – 使用单一样式类启用和禁用按钮
- javascript add event remove event_javascript技巧
javascript-通过remove属性启用和禁用按钮(js removelistener)
这个问题已经在这里有了答案: > Disable/enable an input with jQuery? 17个
我想编写一个程序,以通过remove属性jQuery代码启用和禁用复选框上的按钮.
我尝试过,但是没有用.
$(document).ready(function() {
$('#myCheckBox').on('change', function() {
var x = $(this).attr('value');
if (x == 'on') {
$('#myButton').removeAttr('disabled');
} else if (x == undefined) {
$('#myButton').attr('disabled');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<label for="myCheckBox">
I agree with terms and conditions
<input type="checkBox" id="myCheckBox" />
</label>
<br />
<br />
<input type="button" id="myButton" value="Submit" disabled />
我是jQuery的初学者,请在下面对任何查询发表评论.
解决方法:
使用.is(‘:checked’)而不是求值.也替换:
$('#myButton').attr('disabled'); //Get the value
由:
$('#myButton').attr('disabled','disabled'); //Set the value
设置值.
注意:您可以使用prop()代替:
$("#myButton").prop('disabled', !$(this).is(':checked'));
希望这可以帮助.
attr()/ removeAttr()片段:
$(document).ready(function(){
$('#myCheckBox').on('change',function(){
if( $(this).is(':checked') ){
$('#myButton').removeAttr('disabled');
}else{
$('#myButton').attr('disabled','disabled');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label for="myCheckBox">
I agree with terms and conditions
<input type="checkBox" id="myCheckBox" />
</label>
<br />
<br />
<input type="button" id="myButton" value="Submit" disabled />
prop()片段:
$(document).ready(function(){
$('#myCheckBox').on('change',function(){
$("#myButton").prop('disabled', !$(this).is(':checked'));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label for="myCheckBox">
I agree with terms and conditions
<input type="checkBox" id="myCheckBox" />
</label>
<br />
<br />
<input type="button" id="myButton" value="Submit" disabled />
节点删除(empty()与remove()方法)
一:empty()方法删除节点
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<script src="../Jquery/jquery-3.3.1.js"></script>
<style>
div {
background: #bbffaa;
width: 300px;
height: 200px;
}
</style>
</head>
<body>
<h2>通过empty移除元素</h2>
<div id="test">
<p>p元素1</p>
<p>p元素2</p>
</div>
<button>点击通过jQuery的empty移除元素</button>
<script type="text/javascript">
/**
* empty()只会清空该节点下的子 节点,但本身不会删除
*/
$("button").on(''click'', function() {
//通过empty移除了当前div元素下的所有p元素
//但是本身id=test的div元素没有被删除!!!!!!
$("#test").empty()
})
</script>
</body>
</html>
二:remove方法删除
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<script src="../Jquery/jquery-3.3.1.js"></script>
<style>
.test1 {
background: #bbffaa;
}
.test2 {
background: yellow;
}
</style>
</head>
<body>
<h2>通过jQuery remove方法移除元素</h2>
<div>
<p>p元素1</p>
<p>p元素2</p>
</div>
<div>
<p>p元素3</p>
<p>p元素4</p>
</div>
<button>通过点击jQuery的remove移除元素</button>
<button>通过点击jQuery的remove移除指定元素</button>
<script type="text/javascript">
/**
* 删除节点时需要把事件给销毁掉,这里是为了防止"内存泄漏"
* remove内部会自动操作事件销毁方法
**/
$("button:first").on(''click'', function() {
//删除整个 class=test1的div节点
$(".test1").remove()
})
$("button:last").on(''click'', function() {
//找到所有p元素中,包含了3的元素
//这个也是一个过滤器的处理
$("p").remove("p:contains(''3'')")//传入带参数的,可以散出指定元素
})
</script>
</body>
</html>
asp.net – 如何根据用户角色启用和禁用按钮?
我之前做过,那个按钮应该是可见的或者我没有成功,但是,我无法获得正确的代码(aspx.cs)来禁用按钮,以便它可以在视图中但根本不可访问.
<asp:Button ID="Button4" runat="server" PostBackUrl="~/report.aspx" Text="print in report format" Width="173px" Enabled='<%# HttpContext.Current.User.IsInRole("Admin") %>' />
我希望每当成员登录时,应该禁用“报告”按钮.
解决方法
在html中:
<Button ... Enabled='<%# HttpContext.Current.User.IsInRole("Admin") %>' ... >
或者代码背后:
Button.Enabled = HttpContext.Current.User.IsInRole("Admin");
css – 使用单一样式类启用和禁用按钮
在css
.formBtn {color:#fff; background-color:#518ACD; border-color:#ccc #000 #000 #ccc; font- size:11px; font-weight:bold;}
在HTML中
<html:submit stylevalue="Add"/>
建议我,以便我可以使用相同的类名称为禁用按钮,并以不同的方式显示它(比如背景颜色:灰色).我可能正在使用这样的样式类
在HTML中
<html:submit stylevalue="disabled Add" disabled="true"/>
解决方法
.formBtn:disabled { background-color: grey; }
javascript add event remove event_javascript技巧
网上搜来的,看样子不错,记一笔。//------------------------------------
// heavily based on the Quirksmode addEvent contest winner, John Resig
// addEvent
function addEvent(obj,type,fn){
if(obj.addEventListener) obj.addEventListener(type,fn,false);
else if(obj.attachEvent){
obj["e"+type+fn]=fn;
obj[type+fn]=function(){obj["e"+type+fn](window.event);}
obj.attachEvent("on"+type,obj[type+fn]);
}
}
//------------------------------------
// removeEvent
function removeEvent(obj,type,fn){
if(obj.removeEventListener) obj.removeEventListener(type,fn,false);
else if(obj.detachEvent){
obj.detachEvent("on"+type,obj[type+fn]);
obj[type+fn]=null;
obj["e"+type+fn]=null;
}
}
今天关于javascript-通过remove属性启用和禁用按钮和js removelistener的分享就到这里,希望大家有所收获,若想了解更多关于
本文标签: