基于data-id的twitter bootstrap模式上的echo文本

时间:2014-07-10 06:28:48

标签: javascript php jquery twitter-bootstrap

我正在将data-id传递给twitter bootstrap模型,我可以将其分配给隐藏字段,但是基于data-id具有的内容,我正在尝试回显文本而且我被卡住了

这就是我调用模式的方式,您会注意到第一个链接在goal_holidays中传递data-id,第二个链接在goal_house中传递data-id

<a class="open-GoalDialog" data-toggle="modal" href="#editGoals" data-id="goal_holidays">Edit</a>

<a class="open-GoalDialog" data-toggle="modal" href="#editGoals" data-id="goal_house">Edit</a>

我需要做什么 在模态我需要像这样检查。请注意,这不是我正在使用的实际代码,这是我写的虚拟代码,用于解释我需要做什么

if(data-id = goal_holidays){
echo "holiday";
}else if (data-id = goal_house){
echo "house";
}

这就是我的模态看起来像

<div id="editGoals" class="modal hide fade" data-keyboard="false" data-backdrop="static">
    <div class="modal-header">
        <a type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</a>

        <h3 style="font-size: 18px;" id="myModalLabel"><img src="assets/img/logo_icon.png">Goal Tracker</h3>
    </div>
    <div class="modal-body">
        <div id="message2"></div>
        <form action="dashboard-goals-ajax.php" method="post" name="goaldataform" id="goaldataform"
              class="form-horizontal goaldataform">
            <div class="control-group">
                <label class="control-label goal_label_text"><?php _e('Goal Target'); ?>
                </label>

                <div class="controls">
                    <div class="input-prepend input-append">
                        <span class="add-on">$</span><input type="text" class="input-medium" name="goal_target"
                                                            id="goal_target" value="">
                    </div>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label goal_label_text"><?php _e('How much have you saved towards your goal?'); ?>
                </label>

                <div class="controls">
                    <div class="input-prepend input-append">
                        <span class="add-on">$</span><input type="text" class="input-medium" name="goal_progress"
                                                            id="goal_progress" value="">
                    </div>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label goal_label_text"><?php _e('Goal deadline'); ?>
                </label>

                <div class="controls">
                    <div class="input-prepend input-append">
                        <span class="add-on"></span><input class="input-medium datex" type="text" id="goalDeadline"
                                                           name="goalDeadline">
                    </div>
                </div>
            </div>
            <input type="hidden" name="goal_type" id="goal_type" value=""/>
            <input type="hidden" name="goal_target_submitted">
        </form>
    </div>
    <div class="modal-footer">
        <button data-complete-text="Close" class="dt-btn btn-yellow dt-btn-1 pull-right"
                id="goaldatasubmit" name="goaldatasubmit"><?php _e('Submit'); ?></button>


        <div class="gap-10"></div>

    </div>
</div>

这就是我正在使用的JS将data-id分配给隐藏字段goal_type

$(document).on("click", ".open-GoalDialog", function () {
    var myGoal = $(this).data('id');
    $(".modal-body #goal_type").val(myGoal);

如果有人能帮助我如何基于goal_type数据回显文本,我将非常感激。

1 个答案:

答案 0 :(得分:0)

您的比较部分出错。

if(data-id = goal_holidays){
    echo "holiday";
}else if (data-id = goal_house){
    echo "house";
}

goal_holidaysgoal_house是字符串,而不是变量。

所以,你必须替换那样的代码;

if(data-id == "goal_holidays"){
    echo "holiday";
}else if (data-id == "goal_house"){
    echo "house";
}