duanbipu7601 2014-07-22 17:22
浏览 93
已采纳

如何在Yii2上添加jQuery

I'm trying to use some jQuery on my website. I tried to use the code from This Question

and i can't find my error. I tried to put he code on layot/main.php and on site/index.php and no result. Here is my simple jQuery Code:

 <select name="dropdown" size=1>
<option value="1">option 1</option>
<option value="2">option 2</option>
</select>

<?php
use yii\web\View;
$this->registerJs(' $("select[name="dropdown"]").change(function(){

if ($(this).val() == "2")
    alert("call the do something function on option 2");

});', View::POS_READY);
?>        

Please Help!!

--- EDIT --- It work on this way:

<?php
use yii\web\View;
$this->registerJs("
$('select[name="."dropdown"."]').change(function(){
$("."'#teste'".").html('call the do something function on option '+$(this).val());
if ($(this).val() == '2')
    alert('call the do something function on option 2');

 });", View::POS_READY);
 ?>   
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 Maya的Fbx模型导入Ue4.24后为什么个别部位的UV发生了改变?
      • ¥15 网页设计与开发html
      • ¥15 bin格式的程序文件烧录GD32F105芯片。起始地址填多少?
      • ¥15 python对txt文件的处理
      • ¥25 需要一个能在H5中实现扫码的插件
      • ¥50 ArcGIS或MATLAB实现批量计算整个tif图像的EVI
      • ¥20 两个板子之间CAN通信ID号怎么设置
      • ¥15 两个板子CAN通信的话ID号怎么设置
      • ¥15 vue使用element-ui的el-upload上传图片至服务器,服务端使用的是node.js,图片上传成功,但界面显示不出来,是跨域问题?
      • ¥15 ANSYS APDL循环结果输出