0

我是 JQuery 的新手。我想在按钮单击时传递选定的单选按钮值,并在文本框和组合框中显示选定的单选按钮值。

我不知道怎么做。

我当前的代码如下.displayjobs()显示了带有页面加载值的表格。

function displayjobs() {
    $('#jobsTable').empty();
    $("#jobsTable").append("<tr><th>Id</th><th>Operating System</th><th>Browser</th><th>version</th><th>testscript</th><th>server</th></tr>");
    $.ajax({
        type: 'GET',
        url: "/getJobs",
        dataType: "json",
        success: function (jobs) {
            alert(jobs);
            if (jobs.length == 0) {
                alert("There are no scheduled Jobs");
                $("#jobsTable").hide();
            } else {
                //jobs.forEach(function(job) {
                $.each(jobs, function (key, value) {
                    alert(value.server);
                    var tabString = '<tr><td>' + value.jobid + '</td><td>' + value.os + '</td><td>' + value.browser + '</td><td>' + value.version + '</td><td>' + value.script + '</td><td>' + value.server + '</td><td>' + '<input type="radio" name="joblist" id= ' + value.jobid + 'value=' + value.jobid + '/> </td></tr>';
                    $("#jobsTable").append(tabString);
                });
            }
        }
    });
}

在按钮 onClick showdata() 中,我必须将选定的单选按钮值显示到文本框和 comboboxex

<h3>List Jobs</h3>
        <div>
            <h1 style="padding: 10px;">Jobs In Database</h1>
            <div id="jobTable" style="padding-left: 50px;">
                <div style="padding: 5px; padding-left: 0px;">
                    <table id="jobsTable" border="1">
                    </table>
                    <input type="button" id="show" value="showrecord" onclick="showdata();"/>
                </div>
            </div>
            <br/>           
        </div>


<div id="manage">
                            <div>
                                <label>Operating Systems</label>
                                <select id="OS" onchange="browserlist();">
                                    <option value="win7 32">Windows 7 - 32 </option>
                                    <option value="win7 64">Windows 7 - 64 </option>
                                    <option value="Vista 32">Windows Vista - 32</option>
                                    <option value="Vista 64">Windows Vista - 64</option>
                                    <option value="Win8 X64">Windows 8 - X64</option>
                                </select>
                            </div>
                        <div>
                            <label>Browsers</label>
                            <select id="browsers" onchange="browserDet();">
                                    <option value=""></option>
                            </select>
                        </div>  

                        <div>
                            <label>Versions</label>
                            <select id="version">       
                            </select>
                        </div>  

                        <div>
                            <label>Test Scripts</label>
                            <select id="testscriptlist">
                            <option value=""></option>
                                                    <option value=""></option>
                            </select>
                        </div>  
                        <div>
                            <label>Server:</label>
                            <input type="text" id="server" value="" />
                        </div>

                        <br/>



        </div>      
4

1 回答 1

1
function showdata(){
 var $tr=$('input:radio:checked').parent().parent(); //will give you the  tr
 var jobid= $tr.find("td:eq(0)").html(); //first td text
 var os= $tr.find("td:eq(1)").html(); //second td text....
 .....
 var server=$tr.find("td:eq(5)").html();

 $("#OS").append("<option value='"+os+"' selected>"+os+"</option>"); //to add an option to select
 $("#server").val(server); //to add value to text box

}
于 2013-08-23T05:13:35.057 回答