我在一个页面上有一个表单,然后提交到另一个表单。我想创建一个变量,所以它拉出数字,以便它可以在表单上发布。
<!---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)而不是id的文本(即5033)。
答案 0 :(得分: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');
});
});