0

選択した行から値を取得し、それらをパラメーターとして$.getJSONに渡そうとしています。値を取得することはできますが、リンクをクリックすると、値の前後に奇妙な文字が表示されます。リンク内の文字は、%OA ++++++++++ value +++++++%0Aとして表示されます。

これが私のコードです

var className='';
var Section='';
$('#listsubject tr').click(function () {
            var th = $(this);
            var td = $(this).find('td');

            $.each(td, function (index, item) {
                if (index == 2) className = item.innerHTML;

            });


 $.getJSON('@Url.Action("getStudentList/","Student")',
                { classname: className
                }, function (data) {
   alert('test');
});

親切に私を助けてください。ここで立ち往生

前もって感謝します

編集

コードを試してみると

$.getJSON('@Url.Action("getStudentList/","Student")',
                    { classname: className,
                      section:'A'
                    }, function (data) {
       alert('test');
    });

リンクのセクション部分は問題なく表示されますが、問題はクラス名だけです。

アップデート

フィドルリンク http://jsfiddle.net/gordon/vzTDc/2/

4

1 に答える 1

1

これを試して。今は大丈夫だと思います。

var className = '',
    Section = '';

// you were trying with $('#listsubject tr'), but first tr has no td
// so click should bind with tr from 2nd
// so correct selector will be $('#listsubject tr:gt(0)')

$('#listsubject tr:gt(0)').click(function() {
    var th = $(this);
    var td = $(this).find('td');
    $.each(td, function(index, item) {

        // As you have 2 td with in each row, so the index will be 0 and 1
        // not 2 and 3

        if (index == 0) {
            className = $.trim($(item).text()); // $.trim() will remove spaces
        }
        if (index == 1) {
            Section = $.trim($(item).text());
        }
    });
    console.log('ClassName: ' + className + ', Section: ' + Section);
    $.getJSON('StudentMarks/getSubjectGrading', {
        classname: className,
        section: Section
    }, function(data) {
        alert(data);
    });
});

デモ

于 2012-05-26T15:25:52.130 に答える