如何使用Jquery设置隐藏输入字段的值? [英] How can I set the value of a hidden input field using Jquery?
本文介绍了如何使用Jquery设置隐藏输入字段的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将隐藏的输入字段的值设置为与单击的链接的值相同.
I am attempting to set the value of a hidden input field to the same as the value of a clicked link.
这是我尝试过的无效的方法:
This is what I have attempted which doesnt work:
$(document).ready(function(){
$(".delete_link").click(function(){
var deleteID = $(this).attr("data-value");
$("#delete_value").attr("value") = deleteID;
});
});
正确设置了变量deleteID
.
以及参考表格:
<form name="delete_form" action="delete_post.php" method="POST">
<p>Please confirm you want to delete this post.</p>
<input type="submit" id="delete_submit" name="delete_submit" value="confirm" />
<input type="hidden" id="delete_value" value="" />
</form>
推荐答案
使用val方法
$("#delete_value").val(deleteID);
对于数据属性,您可能还想使用数据方法
also for data attributes you might want to use the data method
$(this).data('value');
链接:
- http://api.jquery.com/val/
- http://api.jquery.com/data/
这篇关于如何使用Jquery设置隐藏输入字段的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文