I am trying to disable all inputs in the form excluding a hidden input with the name __RequestVerificationToken
I tried
$('form :input:not(name=__RequestVerificationToken)').prop('disabled', true);
but its not working, any help would be appreciated.
Apologies, I missed some details -- see below test
<form>
<input value="disable me" />
<input value="disable me" />
<input value="disable me" />
<input name="__RequestVerificationToken" value="not me" />
<br />
<br />
<button>Disable All Except __RequestVerificationToken</button>
</form>
$("button").on("click", () => {
$('form :input').prop('disabled', true); this works
// $('form :input:not(name=__RequestVerificationToken)').prop('disabled', true); // this not
})
You are missing the []
for the attribute selector
$("button").on("click", (e) => { e.preventDefault(); $('form:input:not([name=__RequestVerificationToken])').prop('disabled', true); // ^^ missing braces ^^ })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form> <input value="disable me" /> <input value="disable me" /> <input value="disable me" /> <input name="__RequestVerificationToken" value="not me" /> <br /> <br /> <button>Disable All Except __RequestVerificationToken</button> </form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.