如何使用javascript按下按钮时从滑块获取id?

时间:2014-03-08 05:09:00

标签: javascript php jquery html

下面是我试图从滑块包装器获取模板ID的代码。每当用户选择当前模板的活动模板时,如何从那里获取id? 我尝试使用html方式,但它总是给我模板ID为no 3,总是给出最后一个模板ID

这是html代码:

<!-- slider-->
        <div id="slider-wrapper">
            <div id="slider">
                <div class="template">
                    <h3>Chronological Resume</h3>
                    Traditional Resume Template
                    <img src="images/resumes_image/chronological.png" id="1" alt="Chronological Resume" />
                    <input type="hidden" name="template" value="1"/>
                </div>
                <div class="template">
                    <h3>Functional Resume</h3>
                    Skills-based Resume Template
                    <img src="images/resumes_image/functional.png" id="2" alt="Functional Resume" />
                    <input type="hidden" name="template" value="2"/>
                </div>
                <div class="template">
                    <h3>Combination Resume</h3>
                    Combination of Chronological Resume & Functional Resume
                    <img src="images/resumes_image/combination.png" id="3" alt="Combination Resume" />
                    <input type="hidden" name="template" value="3"/>
                </div>  
            </div> <!-- close for slider-->
        </div> <!-- close for slider-wrapper-->
        <div id="nav">
            <div id="button-previous"><img src="images/icons/prev.png" alt="previous" /></div>
        <div id="button-next"><img src="images/icons/next.png" alt="next" /></div>

试图检索滑块编号的代码:

if ($_SERVER["REQUEST_METHOD"] == "POST"){
 if(isset($_POST['submit'])){
    $template = $_POST['template']; 
    echo $template; 
    exit;
    }
}

1 个答案:

答案 0 :(得分:0)

一个纯粹的javascript / jQuery解决方案:

var sliderNum = $('.active > #template').val();