1

我在一个页面上有一个表格,在提交时它会转到另一个页面上的表格。我想创建一个变量,以便它提取数字,以便可以将其发布在表单上。

<!---these are the thumbs--->
<a id="155a" class="ThumbClick"href="#"><img src="images/thumb/5032.jpg" /></a>
<a id="156a" class="ThumbClick"href="#"><img src="images/thumb/5033.jpg" /></a>             
<a id="157a" class="ThumbClick"href="#"><img src="images/thumb/5034.jpg" /></a>

<!--these represent the number shown when thumb is clicked and the go to other form--->
<div id="call-to-action">
<h2 id="155c" class="image-num">5032</h2>
<h2 id="156c" class="image-num">5033</h2>
<h2 id="157c" class="image-num">5034</h2>
<form  id="quote" method="post" action="quote.php">
    <input type="hidden" name="cat" value="Revision Door" />
    <input type="hidden" name="des" value="" />
    <input type="submit" value="Get A Quote" />
</form>
</div>

<!---these represent the full size image--->
<img id="155b" class="hide1" src="images/fullsize/5032.jpg" />
<img id="156b" class="hide1" src="images/fullsize/5033.jpg" />              
<img id="157b" class="hide1" src="images/fullsize/5034.jpg" />



<!--this is the jquery that makes it all work--->
$(function () {
    $('.ThumbClick').click(function (eb) {
        var $idb = this.id.replace('a', 'b');

        eb.preventDefault();
        $('.show,#' + $idb).toggleClass('show');
    });
    $('.ThumbClick').click(function (ec) {
        var $idc = this.id.replace('a', 'c');

        ec.preventDefault();
        $('#' + $idc).toggleClass('show');
    });
    $('.ThumbClick').click(function () {
        $('#call-to-action').addClass('show');
    });
});

对应于图像,当单击拇指时,.image-num它会显示文本(即 5033)我需要在表单上发布(即 5033)而不是 id。

4

1 回答 1

1

Update your jQuery to add the following:

$(function () {
    $('.ThumbClick').click(function (eb) {
        var $idb = this.id.replace('a', 'b');

        eb.preventDefault();
        $('.show,#' + $idb).toggleClass('show');
    });
    $('.ThumbClick').click(function (ec) {
        var $idc = this.id.replace('a', 'c');

        ec.preventDefault();
        $('#' + $idc).toggleClass('show');
        $('input[name="des"]').val($('#'+ $idc).html()); // <- Add Me
    });
    $('.ThumbClick').click(function () {
        $('#call-to-action').addClass('show');
    });
});

You can also condense all of this into one .click() function, there's no need to have 3.

$(function () {
    $('.ThumbClick').click(function (e) {
        e.preventDefault();

        var $idb = this.id.replace('a', 'b');
        $('.show,#' + $idb).toggleClass('show');

        var $idc = this.id.replace('a', 'c');
        $('#' + $idc).toggleClass('show');
        $('input[name="des"]').val($('#'+ $idc).html()); // <- Add Me

        $('#call-to-action').addClass('show');
    });
});
于 2013-08-14T17:54:34.437 回答