单击复选框时停止触发功能

时间:2015-10-08 02:09:26

标签: javascript php

我使用jquery打印下表。表有两列。一个用于值,另一个用于复选框。 我面临的问题是,当我单击一个复选框时,它会触发仅在单击该值时才会触发的功能。

有人可以告诉我如何在单击复选框时停止触发该功能吗?

打印表格的PHP代码

<table border='1' cellspacing='12' cellpadding='4' style='border-collapse: collapse' width='700' id=topictable >

<?php while ($row = mysql_fetch_assoc($results)) {
    $topic = $row['topic']; 
?>
<tr bgcolor='white'>
<td class='value'><a href='#'><?php $topic ?></a></td>
<td bgcolor='white'width='5%'><input type=checkbox name=chekboxTopic[] value= <?php $topic ?> </td>
</tr>
<?php
}
?>
</table>

Java脚本

$(document).on("click","#topictable td", function() {
    // to set the session variable`enter code here`
    var strSelectedTopic = ($( this ).text());
    alert(strSelectedTopic);
    var switchval = "setsessiontopic";
     var param = "switchval=" + switchval + "&topic=" + strSelectedTopic;
     ajaxSend(param);
    var form = document.getElementById("abcd");
    form.action = "design.php"
    form.target = "_blank";
    form.submit();
    return false;

});

1 个答案:

答案 0 :(得分:0)

夫妻俩。

  1. 关闭输入
  2. 更改应该点击的内容;使其更具体化
  3. 演示: http://jsfiddle.net/dL3s3acn/

    <table border='1' cellspacing='12' cellpadding='4' style='border-collapse: collapse' width='700' id=topictable >
    <?php
        while ($row = mysql_fetch_assoc($results)) {
            $topic = $row['topic'];
    ?>
        <tr bgcolor='white'>
            <td class="value"><a href="#"><?php $topic ?></a></td>
            <td bgcolor="white" width="5%"><input type="checkbox" name="chekboxTopic[]" value="<?php $topic ?>" /></td>
        </tr>
    <?php
        }
    ?>
    </table>
    <script>
    // Click on the class ".value" not "td", that is too broad
    $(document).on("click","#topictable .value", function() {
        // to set the session variable`enter code here`
        var strSelectedTopic = ($(this).text());
        alert(strSelectedTopic);
        var switchval   =   "setsessiontopic";
        var param       =   "switchval="+switchval+"&topic="+strSelectedTopic;
        ajaxSend(param);
        var form        =   document.getElementById("abcd");
        form.action     =   "design.php"
        form.target     =   "_blank";
        form.submit();
        return false;
    });
    </script>