1

ajaxページ付けに使用しているスクリプトがあります

スクリプトもうまく実行されます、

スクリプトをすべての人と共有させてください

function show_tour_type(v,t)
{
    $(".cl_tour_type").html('<div align="center"><img src="<?php echo base_url(); ?>assets/front_assets/images/ajax-loader-large.gif" align="center" style="max-height: 300px; max-width: 300px; min-height: 300px;" alt="image" /></div>');
    var p=v;
    var showresult='';
    var showpagi='';
    $.ajax({
        url:"<?php echo base_url().'ajax/ajax_tour_type_pagination';?>",
        data:{'start':p,'perpage':t},
        type:'POST',
        dataType:'JSON',
        async:true,
        success:function(result){
            pagi = result.pagi;
            uname = result.uname;
            console.log(pagi.cont.perpage);
            result= result.content;
            console.log(result);

            for(i=0;i<result.length;i++)
            {
                showresult+='<div class="tour_type_ajax"><h1>'+result[i].tour_type+'</h1><br/><img src="<?php echo base_url(); ?>'+result[i].type_image+'" style="max-height: 100px; max-width: 180px; min-height: 100px;" alt="image" /><br/><br/><br/><div class="detail_button"><input type="text" id="tour_type'+i+'" value="tour_type'+i+'"/><a href="#!/page_tour_specification" onclick="show_tour_spec('+result[i].tour_type+')">Detail</a></div></div>';
            }
            //showresult+='<div class="cleaner_with_width">&nbsp;</div><div class="cleaner_with_height">&nbsp;</div><div class="cleaner">&nbsp;</div><div class="cleaner_with_height">&nbsp;</div>';
            showpagi+='<table width="20%" height="100%" border="0"><tr>';
            for(i=0;i<pagi.cont.pages;i++)
            {
                if(i==0)
                    showpagi+='<td onclick="show_tour_type('+parseInt(i)+','+pagi.cont.perpage+')"><a href="javascript:void(0);">First</a></td>';
                else if(i==pagi.cont.pages-1)
                    showpagi+='<td onclick="show_tour_type('+parseInt(i)+','+pagi.cont.perpage+')"><a href="javascript:void(0);">Last</a></td>';
                else
                    showpagi+='<td onclick="show_tour_type('+parseInt(i+1)+','+pagi.cont.perpage+')"><a href="javascript:void(0);">'+parseInt(i+1)+'</a></td>';
            }

            showpagi+='</tr></table>';
            $(".cl_tour_type").html(showresult);
            $(".pagenav").html(showpagi);
        }
    });
}


function hii(val)
{
    alert(val);
}

今、私はかなり奇妙な問題に直面しています、

行で

 showresult+='<div class="tour_type_ajax"><h1>'+result[i].tour_type+'</h1><br/><img src="<?php echo base_url(); ?>'+result[i].type_image+'" style="max-height: 100px; max-width: 180px; min-height: 100px;" alt="image" /><br/><br/><br/><div class="detail_button"><input type="text" id="tour_type'+i+'" value="tour_type'+i+'"/><a href="#!/page_tour_specification" onclick="hii('+result[i].tour_type+')">Detail</a></div></div>';

あなたはコードを見つけることができますonclick="hii('+result[i].tour_type+')"

関数を呼び出すことになっていますhii(val)

ここで問題となるのは、関数hiiが呼び出されても、何も警告されないことです。

しかし、私が単純な場合+2+は代わりに書く+result[i].tour_type+

その後、そのアラート2

つまり、関数が正しいことを意味します。

問題は、いくつかの問題があるかもしれないということ+result[i].tour_type+です。

しかし、これに値がない場合は、ajax応答に表示されていないので、値を返します...それでは、なぜhii関数で値を送信しないのでしょうか。

4

1 に答える 1

-1

これは、リテラル文字列を渡しているためです。そのように引用符をラップします。

'...onclick="hii(\''+ result[i].tour_type +'\')"...'

引用符がないと、次のように評価されますhi(somevalue)somevalueは変数ではないため、機能しません。

が機能する理由は、が文字列ではなく整数として評価される'hi('+ 2 +')'ためです。2

于 2013-03-02T11:43:29.227 に答える