简体   繁体   English

如何在onclick的jquery函数中调用值

[英]how can call value in jquery function in onclick

I want add value in jquery function an post it to my php file. 我想在jquery函数中添加值,然后将其发布到我的php文件中。 I call my jquery function whit onclick event but i don't know how can add value. 我称我的jquery函数为白色onclick事件,但我不知道如何增加价值。 I have this input tag: 我有这个输入标签:

 <input type="hidden" name="code" id="code" value="<?php echo $code; ?>"  />

and my onlick event this is: 而我的onlick事件是:

<span onClick="previewed_files(); checkDb();">start</span>

and my checkDb function it is: 而我的checkDb函数是:

    <script type="text/javascript" >

    function checkDb(adscode){
        $.post('myphp.php',{adscode: adscode},function(data){
            $('#mydiv').html(data);}

                        );
            }
  </script>

now I can't call value from input by id code in my checkDb() function in onclick event. 现在,我无法在onclick事件的checkDb()函数中通过ID代码从输入中调用值。 please help me. 请帮我。 thank you 谢谢

Here : 这里 :

<script type="text/javascript" >
function checkDb(adscode){
    $.post('myphp.php',{adscode: adscode, value: $('#code').val()},function(data){
        $('#mydiv').html(data);});
}
</script>

You must check for ajax tutorials to get value in php. 您必须检查ajax tutorials才能在php中获得价值。 You cant get parameter value in function untill you pass in the function. 在传递函数之前,您无法在函数中获取参数值。

to get value of hidden variable - 获得隐藏变量的值-

var value = jQuery('#code').val();

Now, you can use this variable in your funciton. 现在,您可以在函数中使用此变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM