如何在使用jquery的cakephp中单击radion按钮从文本框中添加或删除readonly属性? [英] how we add or remove readonly attribute from textbox on clicking radion button in cakephp using jquery?

查看:279
本文介绍了如何在使用jquery的cakephp中单击radion按钮从文本框中添加或删除readonly属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的cakephp生成的HTML 广播框文本框脚本:

Here is my cakephp generated HTML radio box and text box script:

<input type="radio" id="need_staff_on_site" name="data[CaterRequest][need_staff_on_site]" value="yes" class="staff_on_site"><span>Yes</span>

<input type="radio" id="need_staff_on_site" name="data[CaterRequest][need_staff_on_site]" class="staff_on_site" value="no"><span>No</span>

How many staff?<input type="text" maxlength="3" id="no_of_staff" name="data[CaterRequest][staff_needed]" class="txtboxSml2" readonly="readonly">

jquery脚本

$(document).ready(function(){
   $('.staff_on_site').click(function(){
   $arr=$(this).val();
   if($arr == "yes"){ $("#no_of_staff").removeAttr("readonly"); }
   if($arr == "no"){ $("#no_of_staff").attr("readonly", "readonly"); }
  });
});

Demo jsfiddle链接

推荐答案

在您的案例中,您可以编写以下jquery代码: p>

In your Case you can write the following jquery code:

$(document).ready(function(){

   $('.staff_on_site').click(function(){

     var rBtnVal = $(this).val();

     if(rBtnVal == "yes"){
         $("#no_of_staff").attr("readonly", false); 
     }
     else{ 
         $("#no_of_staff").attr("readonly", true); 
     }
   });
});

这里是小提琴:http://jsfiddle.net/P4QWx/3/

这篇关于如何在使用jquery的cakephp中单击radion按钮从文本框中添加或删除readonly属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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