繁体   English   中英

如何在jquery函数中使用php变量id?

[英]How to use a php variable id in a jquery function?

下面的代码适用于select#B值( B ),但不适用于select#index的变量( $index )。 实际上我需要id是一个变量,并希望jQuery函数对该变量进行操作。

jquery函数:

$(function(){

    $('select#B').change(function(){

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

            $('input#seleted_value').val(this_value);

    });

});

试试吧

$("select#<?php echo $index;?>").change(function(){
     var this_value = $(this).val();

     $('input#seleted_value').val(this_value);
});

做这个

$("select#<?php echo $index;?>").change(function(){

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

    $('input#seleted_value').val(this_value);

});
 $('select#<?=$index?>').change(function(){

要么

 $('select#<?PHP echo $index;?>').change(function(){
   var selector = 'select#<?= $index ?>'; // Work only if short tag is enabled

    OR

    var selector = 'select#<?php echo $index ?>'; 

    $(selector).change(function(){

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM