当前位置: 首页 > news >正文

浅谈监听单选框radio改变事件(和layui中单选按钮改变事件)_javascript技巧

若是只引用jquery的话,监听单选按钮改变事件如下:

<tr><td align="left" class="bigColor">房屋类型</td><td colspan="5"><input type="radio" name="houseType" id="houseType1" value="1">1 土屋<input type="radio" name="houseType" id="houseType2" value="2">2 茅屋<input type="radio" name="houseType" id="houseType3" value="3">3 木屋<input type="radio" name="houseType" id="houseType4" value="4">4 砖瓦平房<input type="radio" name="houseType" id="houseType5" value="5">5 砖瓦楼房<input type="radio" name="houseType" id="houseType6" value="6">6 其他<input type="text" id="houseTypeOther" name="houseTypeOther" maxlength="200"/></td></tr>
/** 字段监听* */$(document).ready(function() {$('input[type=radio][name=houseType]').change(function() {if (this.value == '6') {$("#houseTypeOther").removeProp("readonly");} else {$("#houseTypeOther").attr("value", "");$("#houseTypeOther").prop("readonly", true);}});});

注意:如果是引用了layui的样式和方法,则上面的监听事件失效,被layui接管了,所以应该如下写法:

layui.use(['form', 'element', 'laydate'], function(){var jQuery = layui.jquery,layer = layui.layer,form = layui.form(),element = layui.element();form.on("radio(sex)", function (data) {var sex = data.value;if (this.value == '1') { alert("这是个男孩"); } else if (this.value == '2') { alert("这是个女孩"); } });
});
http://www.lryc.cn/news/149590.html

相关文章:

  • SourceTree安装教程
  • 渗透测试漏洞原理之---【任意文件上传漏洞】
  • Rust多线程编程
  • 什么是 TF-IDF 算法?
  • 干货!耽误你1分钟,教你怎么查自己的流量卡是什么卡?
  • Spring Boot + Vue的网上商城实战入门
  • 云上办公系统项目
  • three.js(九):内置的路径合成几何体
  • 【MySQL系列】索引的学习及理解
  • GPT-4.0技术大比拼:New Bing与ChatGPT,哪个更适合你
  • vnc与windows之间的复制粘贴
  • windows下如何搭建属于自己的git服务器
  • D360周赛复盘:模拟(思维题目)⭐⭐+贪心解决可能的最小和(类似上次)
  • 【C++学习】函数指针
  • A. Copil Copac Draws Trees
  • D359周赛复盘:贪心解决求最小和问题⭐⭐+较为复杂的双层线性DP⭐⭐
  • python基础之miniConda管理器
  • C++算法 —— 分治(1)快排
  • 接口用例设计
  • Selenium超级详细的教程
  • 服务报network error错误
  • 【ES6】利用 Proxy实现函数名链式效果
  • hive部署
  • ip白名单之网段
  • PMP项目管理主要学习内容是什么?
  • 小米面试题——不用加减乘除计算两数之和
  • Mysql 日志管理 数据备份
  • Java小记-腾讯2020校招-后台-逛街
  • FFmpeg5.0源码阅读——FFmpeg大体框架
  • 【算法刷题之字符串篇】