admin管理员组文章数量:1402788
I am trying to disable all elements of Div tag. I get success on input types. But not able to disable links. I have also tried this, but it is not working. Here is the code I have tried(But it works for input only):
$('#EditorRows *').attr('disabled', true);
I know disable for input types but I want to achieve that type of mechanism for links.
1st PartialView Code:
<div id="Part2">
<div id="EditorRows">
<%= Html.ActionLink("Add another...", "Add", null, new { id = "addItem" }) %>
<%Html.RenderPartial("_InsertServices", Model);%>
</div>
<div id="DontAppend">
<input type="button" id="btnEdit" value="Edit" hidden="hidden"/>
<input type="button" id="btnDone" value="Done" />
</div>
</div>
2nd PartialView
<div class="EditorRow">
<% using (Html.BeginCollectionItem("services"))
{ %>
<table id="table1">
<tr><td>
NOS:</td><td>
<%:Html.DropDownListFor(model=>model.Id,(SelectList)ViewData["crmServiceType"] as SelectList,"---")%>
</td>
<td>
Comment:</td><td>
<%=Html.TextBoxFor(model => model.Comment, new { size = "20" })%></td>
<td>
<a href="#" class="deleteRow">delete</a>
</td>
</tr>
</table>
<% } %>
</div>
script:
$("#addItem").click(function () {
$.ajax({
url: this.href,
cache: false,
success: function (html) { $("#EditorRows").append(html); }
});
return false;
});
$("a.deleteRow").live("click", function () {
$(this).parents("div.EditorRow:first").remove();
return false;
});
$('#btnDone').click(function () {
$('#EditorRows *').attr('disabled', true);
}
$('#btnEdit').click(function () {
$('#EditorRows *').attr('disabled', false);
}
I am trying to disable all elements of Div tag. I get success on input types. But not able to disable links. I have also tried this, but it is not working. Here is the code I have tried(But it works for input only):
$('#EditorRows *').attr('disabled', true);
I know disable for input types but I want to achieve that type of mechanism for links.
1st PartialView Code:
<div id="Part2">
<div id="EditorRows">
<%= Html.ActionLink("Add another...", "Add", null, new { id = "addItem" }) %>
<%Html.RenderPartial("_InsertServices", Model);%>
</div>
<div id="DontAppend">
<input type="button" id="btnEdit" value="Edit" hidden="hidden"/>
<input type="button" id="btnDone" value="Done" />
</div>
</div>
2nd PartialView
<div class="EditorRow">
<% using (Html.BeginCollectionItem("services"))
{ %>
<table id="table1">
<tr><td>
NOS:</td><td>
<%:Html.DropDownListFor(model=>model.Id,(SelectList)ViewData["crmServiceType"] as SelectList,"---")%>
</td>
<td>
Comment:</td><td>
<%=Html.TextBoxFor(model => model.Comment, new { size = "20" })%></td>
<td>
<a href="#" class="deleteRow">delete</a>
</td>
</tr>
</table>
<% } %>
</div>
script:
$("#addItem").click(function () {
$.ajax({
url: this.href,
cache: false,
success: function (html) { $("#EditorRows").append(html); }
});
return false;
});
$("a.deleteRow").live("click", function () {
$(this).parents("div.EditorRow:first").remove();
return false;
});
$('#btnDone').click(function () {
$('#EditorRows *').attr('disabled', true);
}
$('#btnEdit').click(function () {
$('#EditorRows *').attr('disabled', false);
}
Share
Improve this question
edited May 23, 2017 at 12:27
CommunityBot
11 silver badge
asked Mar 6, 2013 at 12:53
DhwaniDhwani
7,62818 gold badges81 silver badges143 bronze badges
10
- disable? what do you mean. It's only input fields who support this attribute. You can hide the div instead. – Tommy Bjerregaard Commented Mar 6, 2013 at 12:54
-
I'm pretty sure that
<a>
elements don't have adisabled
property, but I might be wrong. Do you want to grey them out, have nothing happen when you click them, hide them or something else? – h2ooooooo Commented Mar 6, 2013 at 12:55 - @h2ooooooo, i want that nothing happen when I click on it. – Dhwani Commented Mar 6, 2013 at 12:56
- then make cursor :none – supersaiyan Commented Mar 6, 2013 at 12:56
- @TommySorensen, I dont want to hide, Yes I can fadeto it but I want it to be away from clicking. – Dhwani Commented Mar 6, 2013 at 12:56
6 Answers
Reset to default 3To disable links use this
$('div a').unbind('click');
Ore in your case:
$('#btnDone').click(function () {
var $rows = $('#EditorRows');
$rows.find('input, select, textarea').attr('disabled', true);
$rows.find('a').unbind('click');
}
try this
$('#EditorRows').find('a').each(function(){
$(this).replaceWith($(this).text());
});
Update
To disable :
$('#EditorRows').find('a').bind('click', false);
To enable :
$('#EditorRows').find('a').unbind('click', false);
$('div').find(':input').prop('disabled',true);//this line will this able all inputs including buttons.
$('div').find('a').each(function(){
$(this).removeAttr('href');
$(this).unbind('click');
});//this will take care of the links
I think this will take care of the problem
use off method of jquery.
$('#Yourdiv a').off('click');
$('#yourDiv').find('input').attr('disabled',true);
or else simple is just return false when anchor clicked.
$('#Yourdiv a').on('click',function(e)
{
return false; // or e.preventDefault();
});
It works for input only because they have disable
attribute. To disable link try
if you want just to delete the link redirect.
$("#youdivname").find('a').removeAttr('href')
This will active it again :
$("#yourdivname").find('a').attr('href','link')
where link
is the redirect.
The first solution that came to mind, but it does not pretend to be elegant http://jsbin./icijox/4/edit
本文标签: javascriptHow to disable amp enable all contents of a DivStack Overflow
版权声明:本文标题:javascript - How to disable & enable all contents of a Div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744342202a2601543.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论