如何从JQuery中的表行中提取PHP值以便以后使用?

时间:2016-06-17 22:41:16

标签: javascript php jquery twitter-bootstrap-3

我有一个Button,在表格中填充了所有行。我希望能够将行“$ row [auditID]”的值放在我的模态中,以便能够使这个删除按钮工作。弹出警报,但Modal不会隐藏,我的删除操作不起作用(不删除审计)。

<a href=\"#\" id=\"$row[auditID]\" class='btn btn-danger  btn-xs' role='button' data-toggle='modal' data-target='#question_alert' Title=\"Remove\" >Remove</span>   </a>";

<!-- modal pop up for Deleting a audit -->
<div class="modal fade" style="z-index:10000" id="question_alert" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
            <h4 class="modal-title">Audit Delete Confirmation</h4>
            </div>
            <div class="modal-body"id="myModal1">
                <h3>Are you sure you want to <strong>DELETE</strong> this Audit? You will not be able to get it back.</h3>
            </div>
            <div class="modal-footer">
            <form method = "POST">
                <input type="button" id="yes_delete" value="Yes " name="deleteaudit" />
                <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
            </form> 
            </div>
        </div>
    </div>
</div>

JQuery脚本:

<script> 
 $("#yes_delete").click(function(){
var auditID = this.id;
//alert("delete test");
    $.post("edit_audits.php?action=delete&auditID="+auditID,{
    function(data){
        alert("Audit Deleted");
        $('question_alert').modal('hide');
        window.location.reload();
        }
        }); 
    }); 
</script>

2 个答案:

答案 0 :(得分:0)

这样的东西?

将您的PHP值放入如下标记:

    <a href="#" data-mylink="<?php echo $yourPHPVar; ?>" class='btn btn-danger  btn-xs' role='button' data-toggle='modal' data-target='#question_alert' Title="Remove" ><span>Remove</span> </a>

jsFiddle Demo

$('#question_alert').on('shown.bs.modal', function (e) {
	var btn = $(e.relatedTarget);
	var linked = btn.data('mylink');
	$('#audNo').text(linked);
// Or:
//	var modal = $(this);
//	modal.find('.modal-body h3 span#audNo').text(linked);
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<a href="#" id="bob" data-mylink="Fred" class='btn btn-danger  btn-xs' role='button' data-toggle='modal' data-target='#question_alert' Title="Remove" ><span>Remove</span> </a>

<!-- modal pop up for Deleting a audit -->
<div class="modal fade" style="z-index:10000" id="question_alert" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
            <h4 class="modal-title">Audit Delete Confirmation</h4>
            </div>
            <div class="modal-body"id="myModal1">
                <h3>Are you sure you want to <strong>DELETE</strong> Audit number <span id="audNo"></span>? You will not be able to get it back.</h3>
            </div>
            <div class="modal-footer">
            <form method = "POST">
                <input type="button" id="yes_delete" value="Yes " name="deleteaudit" />
                <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
            </form> 
            </div>
        </div>
    </div>
</div>

答案 1 :(得分:0)

我会做这样的事情

TARGET_LINE1 = r'someString'
TARGET_LINE2 = r'someString2'
TARGET_LINES = [TARGET_LINE1, TARGET_LINE2]
commentsMade = 2

def replaceLine(pattern, replacement, line, adding):

    #global commentsMade  # =========> Doesn't work. Uncommenting this does!!!!

    match = re.search(pattern, line)
    if match:
        line = re.sub(pattern, replacement, line)
        print 'Value before = %d ' % commentsMade
        commentsMade += adding
        print 'Value after = %d ' % commentsMade
    return line

def commentLine(pattern, line):
    lineToComment = r'(\s*)(' + pattern + r')(\s*)$'
    return replaceLine(lineToComment, r'\1<!--\2-->\3', line, +1)

def commentPomFile():
    with open('pom.xml', 'r+') as pomFile:
        lines = pomFile.readlines()
        pomFile.seek(0)
        pomFile.truncate()

        for line in lines:
            if commentsMade < 2:

                for targetLine in TARGET_LINES: # ===> Why this works???

                    line = commentLine(targetLine, line)

            pomFile.write(line)

if __name__ == "__main__":
    commentPomFile()

这是在jQuery函数中。确保将jQuery脚本标记放在页面顶部,以便在此函数之前加载jQuery

<a href="javascript:void(0)" class='btn btn-danger btn-xs btn-remove' data-id="<?=$row["auditID"]?>" role='button' data-toggle='modal' data-target='#question_alert' Title="Remove" >Remove</span></a>

<!-- modal pop up for Deleting a audit -->
<div class="modal fade" style="z-index:10000" id="question_alert" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
            <h4 class="modal-title">Audit Delete Confirmation</h4>
            </div>
            <div class="modal-body"id="myModal1">
                <h3>Are you sure you want to <strong>DELETE</strong> this Audit? You will not be able to get it back.</h3>
            </div>
            <div class="modal-footer">
            <form method = "POST">
                <input type="button" id="yes_delete" value="Yes " name="deleteaudit" />
                <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
            </form> 
            </div>
        </div>
    </div>
</div>

请记住,我没有运行它,因为我没有所需的所有数据。您可能需要稍微调试一下,因为它是盲编码。