对于单击锚标记时输入的HTML文本,将readonly属性设置为false [英] Set readonly property to false for an HTML text input on clicking an anchor tag

查看:82
本文介绍了对于单击锚标记时输入的HTML文本,将readonly属性设置为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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

My 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

Alternate JavaScript

<script type="text/javascript">
    $(document).ready(function () {
        console.log("document ready")
        $('#Aname').live('click', function () {
            $("#name").attr("readonly", false);
        });
    });
</script>

我想做的是在单击相应的锚点字段时将相应的输入文本字段的readonly属性设置为false.我的JavaScript脚本都不起作用.

What I am trying to do is set readonly attribute of the corresponding input text field to false on click of the corresponding anchor field. None of my JavaScript scripts works.

解决方案:组合@KaraokeStu之后,@ bipin答案 我正在使用asp.net 4.5

Solution: after combining @KaraokeStu, @bipin answers I am using 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");
       });

    });

推荐答案

更改元素的只读属性..useprop()

change the readonly property of an element..use prop()

 $("#name").prop('readonly', false);

链接了解有关prop()和attr( )

link to read more about prop() and attr()

这篇关于对于单击锚标记时输入的HTML文本,将readonly属性设置为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆