博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在变更事件中使用广播?
阅读量:2380 次
发布时间:2019-05-10

本文共 2144 字,大约阅读时间需要 7 分钟。

本文翻译自:

I have two radio button on change event i want change button How it is possible? 我在更改事件上有两个单选按钮我想要更改按钮怎么可能? My Code 我的密码

AllotTransfer

Script 脚本


#1楼

参考:


#2楼

You can use this which refers to the current input element. 您可以使用this它指的是当前input元素。

$('input[type=radio][name=bedStatus]').change(function() {    if (this.value == 'allot') {        alert("Allot Thai Gayo Bhai");    }    else if (this.value == 'transfer') {        alert("Transfer Thai Gayo");    }});

Note that you are comparing the value against allot in both if statements and :radio selector is deprecated. 请注意,您已在if语句和:radio选择器均已弃用的情况下,将值与allot比较。

In case that you are not using jQuery, you can use the document.querySelectorAll and HTMLElement.addEventListener methods: 如果您不使用jQuery,则可以使用document.querySelectorAllHTMLElement.addEventListener方法:

var radios = document.querySelectorAll('input[type=radio][name="bedStatus"]');function changeHandler(event) {   if ( this.value === 'allot' ) {     console.log('value', 'allot');   } else if ( this.value === 'transfer' ) {      console.log('value', 'transfer');   }  }Array.prototype.forEach.call(radios, function(radio) {   radio.addEventListener('change', changeHandler);});

#3楼

An adaptation of the above answer... 以上答案的改编...

$('input[type=radio][name=bedStatus]').on('change', function() { switch ($(this).val()) { case 'allot': alert("Allot Thai Gayo Bhai"); break; case 'transfer': alert("Transfer Thai Gayo"); break; } });
 Allot Transfer


#4楼

$(document).ready(function () {    $('#allot').click(function () {        if ($(this).is(':checked')) {            alert("Allot Thai Gayo Bhai");        }    });    $('#transfer').click(function () {        if ($(this).is(':checked')) {            alert("Transfer Thai Gayo");        }    });});


#5楼

A simpler and cleaner way would be to use a class with @Ohgodwhy's answer 一种更简单,更简洁的方法是将类与@Ohgodwhy的答案一起使用

Script 脚本

​$( ".rButton" ).change(function() {    switch($(this).val()) {        case 'allot' :            alert("Allot Thai Gayo Bhai");            break;        case 'transfer' :            alert("Transfer Thai Gayo");            break;    }            });​

#6楼

upiBank

转载地址:http://kfexb.baihongyu.com/

你可能感兴趣的文章
周国平:教育的七条箴言
查看>>
应用程序初始化失败问题的解决
查看>>
开启Windows 7远程桌面功能的做法
查看>>
有关error PRJ0003错误的思考
查看>>
韩少功:怎么赚钱
查看>>
如何煮鸡粥
查看>>
实现自定义对话框程序快捷键的两种方法
查看>>
如何对抗微软霸权,google给我们上了一课
查看>>
未能将基于用户的Visual C++项目设置保存到user文件错误的解决
查看>>
获取windows版本信息的做法
查看>>
打开文件对话框在xp和win7上的实现文件任意多选
查看>>
略谈如何创建一个监控线程
查看>>
苯事两则
查看>>
批处理实现添加java环境变量
查看>>
关于sizeof运算符的一些理解
查看>>
比你更自信,比你更勇敢
查看>>
关于jacob支持BSTR类型的经验总结
查看>>
对Jscript操作注册表接口的一点不解
查看>>
开发一个软件平台的一些心得体会
查看>>
凤凰岭一日游
查看>>