0

我正在尝试开发我的网站。有一张我作为按钮制作的表格。我用 JavaScript 得到按钮的值,如下所示:

<script>
    function setvalue(values) {
        document.getElementById('posisi').value = values;
    }
</script>

我的表格的 HTML:

<table width="1023" height="248" border="1">
  <tr>
    <th colspan="2" scope="col">A1</th>
    <th colspan="2" scope="col">A2</th>
    <th colspan="2" scope="col">A3</th>
</tr>
<tr>
    <td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down',   parent : this, width : '270px' });setvalue(this.value);" value="A1.4" /></td>
    <td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down',   parent : this, width : '270px' });setvalue(this.value);" value="A1.8" /></td>
    <td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down',   parent : this, width : '270px' });setvalue(this.value);" value="A2.4" /></td>
    <td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down',   parent : this, width : '270px' });setvalue(this.value);" value="A2.8" /></td>
    <td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down',   parent : this, width : '270px' });setvalue(this.value);" value="A3.4" /></td>
    <td><div align="center"><input type="button" onclick="popup_window_show('#sample', { pos : 'tag-right-down',   parent : this, width : '270px' });setvalue(this.value);" value="A3.8" /></td>
</tr>
</table>

我尝试使用此 JavaScript 操作背景颜色:

<script type="text/javascript">
var htmlobjek;
$(document).ready(function(){ 
     var pid = "document.getElementById('posisi').value = values";
    $.ajax({
        url: "cek.php",
        data: "pid="+posisi,
        cache: false,
        success: function(data) {

我的算法当我的 SQL 在 cek.php 中成功时,我将回调并显示在当前页面中以操纵表格背景颜色。

在 cek.php 我的 SQL 是这样的:

SELECT ..
FROM..
WHERE posisi='S_POST[posisi]'

我将计算结果(使用 this mssql_num_row(sql))。如果结果有值,表格的背景颜色将为红色。如果不是,它将是绿色的。这就是让我感到困惑的地方。对我的网站有任何想法吗?我希望你明白我的意思。

4

2 回答 2

2

你应该使用这样的成功功能......

 success: function() 
{

   if(rsp.success)
   {

在这里设置rsp为背景色}

 }
于 2013-04-03T10:14:35.050 回答
1
var ajaxCall = $.ajax({
    url: "cek.php",
    type:'POST',
    data: {"data": i},
    cache: false,
}).done( function (data) {
    $("#cek").val(data);
}).fail( function () {
    alert('I can not send ajax here');
});

// Now anywhere in your script:
ajaxCall.done( function (data) {
    var k = $("#cek").val();
    // You can now even do:
    // var k = data;
    if(k == "0"){
        $(".data").css("background-color", "#00CC00");//green
    }
    else {
        $(".data").css("background-color", "#FF0000");//red
    }
});
于 2013-04-12T08:18:14.853 回答