【问题标题】:Pull information based on selection根据选择拉取信息
【发布时间】:2013-08-14 17:45:15
【问题描述】:

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

<!---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。

【问题讨论】:

  • 所以你想要它以便无论哪个&lt;h2&gt; 被点击它里面的数字都与表单一起提交?你也在使用/能够使用 jQuery 吗?

标签: php javascript forms variables input


【解决方案1】:

更新您的 jQuery 以添加以下内容:

$(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');
    });
});

你也可以把所有这些都浓缩成一个.click()函数,不需要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');
    });
});

【讨论】:

  • 我需要第二个隐藏输入的值反映 h2 标签中显示的数字。我现在设置它的方式然后单击 thumb1 显示 pic1 并显示 image-num1,如果 thumb2 则显示 pic2 和 image-num2 等等。
  • @user2517352 thumb1、thumb2 等与包含数字的&lt;h2&gt; 元素有什么关系?您还可以将拇指 1、拇指 2 等的代码编辑到您的问题中吗?
  • 它不起作用,而且它使我的#call-to-action div 没有出现。
  • @user2517352 我的函数命名出错了,我的错。查看我的编辑。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-15
  • 2020-10-10
  • 2015-05-19
相关资源
最近更新 更多