jQuery的ATTR(只读)函数不工作 [英] jquery attr(readonly) function not working

查看:155
本文介绍了jQuery的ATTR(只读)函数不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与AST.Net和jQuery 1.8.3工作。

I am working with AST.Net and jQuery 1.8.3.

我想打一个文本框的只读属性是在页面加载真假脚本运行时。我的code是这样的:

I want to make a textbox's readonly property to be true on pageload and false when a script runs. My code goes like this:

  function showdiv() {

    $("#diviv").fadeIn("slow");
    $("#txtname").attr('readonly', false);
    $("#txtmobile").attr('readonly', false);
    $("#txtemail").attr('readonly', false);
}

我想使这三个文本框的只读属性为假时,函数 showdiv 运行。我也是使得脚本运行时的div可见。但它不是使它假的。请给我一些suggessions如何使它运行,并告诉我问题出在哪里。

I want to make the readonly property of these three textboxes to be false when the function showdiv runs. Also I am making a div visible when the script runs. But it's not making it false. Please give me some suggessions how to make it run and tell me where the problem is.

推荐答案

只读是一个布尔属性,这意味着如果它是present,不管有什么样的价值,它会被设置。由于属性始终是字符串,你将它设置为假。使用道具来代替。

Readonly is a boolean attribute, which means that if it is present, no matter what value it has, it will be set. Since attributes are always strings, you are setting it to "false". Use prop instead.

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

这篇关于jQuery的ATTR(只读)函数不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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