我的 HTML:
<div class="profileForm">
<fieldset>
<label>Name<input type="text" id="name" name="name" runat="server" readonly=""/></label>
<label>Email<input type="email" id="email" name="email" runat="server" readonly=""/></label>
<label>Date Of Birth<input type="date" id="dob" name="dob" runat="server" readonly=""/></label>
<label>Address<input type="text" id="address" name="address" runat="server" readonly=""/></label>
<label>City<input type="text" id="city" name="city" runat="server" readonly=""/></label>
<label>State<input type="text" id="state" name="state" runat="server" readonly=""/></label>
<label>Country<input type="text" id="country" name="country" runat="server" readonly=""/></label>
<label>Access Level<input type="text" id="accessLevel" name="accessLevel" runat="server" readonly=""/></label>
</fieldset>
</div>
<div class="profileEdit">
<fieldset>
<label><a href="#" id="Aname">edit</a></label>
<label><a href="#" id="Aemail">edit</a></label>
<label><a href="#" id="Adob">edit</a></label>
<label><a href="#" id="Aaddress">edit</a></label>
<label><a href="#" id="Acity">edit</a></label>
<label><a href="#" id="Astate">edit</a></label>
<label><a href="#" id="Acountry">edit</a></label>
</fieldset>
</div>
我的 JavaScript
<script src="Scripts/jquery-1.7.1.js"></script>
<script type="text/javascript">
$(document).ready(function () {
console.log("document ready")
$("profileEdit label a").click(
function (e) {
if (this.attr("id") == "Aname") {
$("#name").attr("readonly", false);
}
});
});
</script>
备用 JavaScript
<script type="text/javascript">
$(document).ready(function () {
console.log("document ready")
$('#Aname').live('click', function () {
$("#name").attr("readonly", false);
});
});
</script>
我要做的是readonly
在单击相应的锚字段时将相应输入文本字段的属性设置为 false。我的 JavaScript 脚本都不起作用。
解决方案:结合@KaraokeStu 后,@bipin 回答我使用的是asp.net 4.5
$(document).ready(function () {
console.log("document ready")
$('.profileEdit label a').live('click', function () {
alert("ctl00_ContentPlaceHolder1_" + this.id.substring(1, this.id.length));
$("#" + "ctl00_ContentPlaceHolder1_" + this.id.substring(1, this.id.length)).prop('readonly', false);
console.log($("#" + "ctl00_ContentPlaceHolder1_" + this.id.substring(1, this.id.length)).attr('readonly'))
$("#" + "ctl00_ContentPlaceHolder1_" + this.id.substring(1, this.id.length)).focus();
alert("done");
});
});