jQuery Onclick更改隐藏参数并提交 [英] Jquery Onclick Change hidden parameter and submit
本文介绍了jQuery Onclick更改隐藏参数并提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用php和jquery.我已经创建了一个像这样的div列表
Hi i'm using php and jquery. I have create dinamically a list of a div like that
<div class="divclass" id="<?php echo $i-1;?>">
<a href=" <?php echo $this->url(array('controller'=>'controller name','action'=>'action name'));?>">
<span>Date: </span>
</a>
</div>
我的javasctipt脚本是,我选择单击的ID的名称,将隐藏参数设置为ID的名称,我想提交表单
My javasctipt script is, i pick the name of the id clicked, i set the hidden parameter to the name of the id and i want to submit the form
<script type="text/javascript">
$(document).ready(function() {
$('.divclass').click(function(){
var idarray = $(this).attr("id");
document.getElementById('testo').value=idarray;
document.forms["prova"].submit();
});
});
表格为:
<form id="prova" method="post" action="<?php echo Zend_Controller_Front::getInstance()->getBaseUrl().'/controller-name/action-name';?>">
<input type="hidden" value="" id="testo">
</form>
</script>
但是在下一页中,我没有post参数.
But in the next page i don't have the post parameter.
推荐答案
您需要将name
属性赋予#testo
,然后尝试以下操作:
You need to give name
attribute to #testo
and then try this:
例如
<input type="hidden" value="" id="testo" name="testo">
您的表单在<script>
标签内,将其放置在<script>
标签之外.
Your form is within <script>
tag, Place it outside of <script>
tag.
并像下面那样在DOM中编写以下代码:
and write following code within DOM ready like follwing:
<script type="text/javascript">
$(function() {
// after DOM ready
$('.divclass').click(function(){
var idarray = $(this).attr("id"); // or this.id do the same thing
$('#testo').val(idarray); // set value to testo
$("form#prova").submit(); // submit the form
});
});
</script>
这篇关于jQuery Onclick更改隐藏参数并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文