dongyong1400 2015-03-07 08:48
浏览 290

单击div而不是点击提交然后传递参数

I've got a form with a submit button on a form that opens up a nested php page within a div on my page.

All I want to do is hide the submit button, and instead replace this with clicking one of the divs and thus running a script called showBiog(key), which then passes key to the form for submitting.... help... ;-)

<script type="text/javascript">
$(function() {
// Handler for .ready() called.
$('#SubmitForm').submit(function( event ) {

    $.ajax({
            url: 'test2.php',
            type: 'POST',
            dataType: 'html',
            data: $('#SubmitForm').serialize(),
            success: function(content)
            {
                $("#DisplayDiv").html(content);
            }  
    });

    event.preventDefault();
});

});
</script>

HTML is:

 <form id="SubmitForm" method="post">
        <div id="SubmitDiv" style="background-color:black;">
            <button type="submit" class="btnSubmit">Submit</button>
        </div>
</form>

<div class="test" onClick="showBiog(1)"><p>1</p></div>
<div class="test" onClick="showBiog(2)"><p>2</p></div>
<div class="test" onClick="showBiog(3)"><p>3</p></div>
<div class="test" onClick="showBiog(4)"><p>4</p></div>
  • 写回答

3条回答 默认 最新

  • duanchen6423 2015-03-07 08:52
    关注

    Just remove the button element, and do something like:

    $('#myspecificdiv').on('click', function() {
         $('#SubmitForm').submit();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真