获取父信息并将其传递给隐藏的表单 [英] Getting and passing parent info to hidden form

查看:82
本文介绍了获取父信息并将其传递给隐藏的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WordPress插件(称为postRatings)中,当用户按下嵌套图像时,他会在页面上添加喜欢".我想将该信息传递给隐藏表单.

In a WordPress plugin (called postRatings) when a user presses a nested image he adds a "like" to the page. I want to pass that info to a hidden form.

因此,当用户单击img(触发插件功能的原因)时,我想获取该图像的父span中的序列号,并将其作为值传递给隐藏的 input.

So when user clicks the img (that's what triggers the plugin functionality), I want to get the serial number that is in the parent span of that image, and pass it as a value to my hidden form input.

在父范围ID名称的末尾显示的是序列号.我在下面的HTML代码中将其写为"XXXX".

Thing is the serial number is displayed at the end part of the parent span id name. I wrote it in the HTML code below as “XXXX”.

我试图(仅)获取该数字并将其传递给隐藏输入的值.我开始编写JavaScript代码,但不知道如何继续.

I am trying to get that number (only) and pass it to the value of my hidden input. I started writing the JavaScript code but don't know how to continue.

HTML:

<span id="post-ratings-XXXX" class="post-ratings">
   <img class="post-ratings-image" src="1_on.gif">
</span>
<form>
<input type="hidden" id="supportedCheck"  name="supportedCheck" value="#" 
 maxlength="19"/>
</form>

JavaScript

$('.post-ratings-image').click(function(){
$('#supportedCheck').val ......?
});

推荐答案

您可以使用以下

$('.post-ratings-image').click(function(){
    $('#supportedCheck').val($(this).parent('span')[0].id.split('-')[2]);
});

小提琴演示

这篇关于获取父信息并将其传递给隐藏的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆