Change a hidden input's value with jquery/javascript

眉间皱痕 提交于 2019-12-11 10:25:01

问题


I have some hidden input values that I would like to have be changed to a certain value once a user clicks on a link.


回答1:


$('.someLink').click(function(){
    $('.someHiddenInput').val('new value');
});

I think this is what you mean.

HTML would look something like:

<a href="#" class="someLink">click me to change value</a>
<input type="hidden" name="hiddenVal" class="someHiddenInput" value="old value" />



回答2:


<input type="hidden" id="txtTextHdn" name="txtTextHdn" value="Y" />
<a href="#" id="testLink">Click Me!</a>

$("#testLink").click(function () {
    alert($("#txtTextHdn").val());
    $("#txtTextHdn").val('X');
    alert($("#txtTextHdn").val());
})

This should work.




回答3:


Do something like this:

JAVASCRIPT:

$(*link selector*).click(function(){
    $(*hidden selector*).val();
});

Here is a demo: http://jsfiddle.net/UbScn/



来源:https://stackoverflow.com/questions/14443687/change-a-hidden-inputs-value-with-jquery-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!