jQuery插件icheck复选框的使用方法

1 icheck插件的介绍

官网:iCheck官网地址

2 icheck的CDN引用方式

如果不愿意下载插件,可以通过CDN引入插件css和js

<link href="http://cdn.bootcss.com/iCheck/1.0.2/skins/all.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/iCheck/1.0.2/icheck.min.js"></script>

3 icheck—动态设置选中

    <input id="checkbox" type="checkbox" name="checkbox" value="1"> 复选框

假设有复选框,现在我们通过其进行演示:
(1) 复选框选中

$('input[type=checkbox]').iCheck('check');

(2) 复选框取消选中

$('input[type=checkbox]').iCheck('uncheck');

(3) 将选框的状态反向切换

$('input[type=checkbox]').iCheck('toggle');

(4) 选框禁用

$('input[type=checkbox]').iCheck('disable');

(5) 选框取消禁用

$('input[type=checkbox]').iCheck('enable');

4 icheck—回调

(1) ifChanged:选框状态改变时触发

$('input[type=checkbox]').on('ifChanged', function(){
})

(2) ifChecked:选框选中时触发

$('input[type=checkbox').on('ifChecked', function(){
})

(3) ifUnchecked:选框取消选中时触发

$('input[type=checkbox').on('ifUnchecked', function(){
})

5 举例

5.1

  <body>
      <input id="radio_1" type="radio" name="radio" value="1"> 单选1
      <input id="radio_2" type="radio" name="radio" value="2"> 单选2 

<script>
      // 获取当前已选中的radio value
       $('input:radio[id^="radio_"]:checked').val();
       $(function () {
         $('input:radio[id^="radio_"]:checked').on('ifClicked', function (event) {
         //当点击某个选中的radio,获取当前的 radio 用 $(this).val(); 
           $(this).val(); 
         });
       });
</script>
 </body>
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要通过接口实现语音播报,您需要使用一个支持 TTS 的语音 API。一些常用的语音 API 包括 Google Cloud Text-to-Speech、Amazon Polly 和 Microsoft Azure Cognitive Services。 以下是一个简单的示例脚本,它使用 jq 命令和 Google Cloud Text-to-Speech API 来将天气预报转换为语音并播放: ``` #!/bin/bash API_KEY="YOUR_API_KEY" CITY="New York" WEATHER_URL="http://api.openweathermap.org/data/2.5/weather?q=$CITY&appid=$API_KEY" LAST_WEATHER_FILE="last_weather.txt" LAST_WEATHER=$(cat $LAST_WEATHER_FILE 2>/dev/null) # Get current weather CURRENT_WEATHER=$(curl -s $WEATHER_URL | jq -r '.weather[0].description') # Check if there's a new weather report if [ "$LAST_WEATHER" != "$CURRENT_WEATHER" ]; then # Update last weather file echo "$CURRENT_WEATHER" > $LAST_WEATHER_FILE # Convert weather report to speech using Google Cloud Text-to-Speech curl -s -X POST -H "Content-Type: application/json" \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ --data "{ 'input':{ 'text':'The current weather in $CITY is $CURRENT_WEATHER.' }, 'voice':{ 'languageCode':'en-US', 'name':'en-US-Wavenet-F' }, 'audioConfig':{ 'audioEncoding':'MP3' } }" "https://texttospeech.googleapis.com/v1/text:synthesize" | jq -r '.audioContent' | base64 --decode > weather.mp3 # Play weather report using a media player mpg123 weather.mp3 fi ``` 这个脚本会从 OpenWeatherMap API 获取当前天气状况,检查它是否与上一次运行时的状况不同,如果有新的状况,则将天气预报转换为语音并通过 Google Cloud Text-to-Speech API 播放它。您可以根据自己的需求修改脚本,并使用不同的语音 API 来实现语音播报。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值