我有一个表单的提交类型为图像的数量。每个图像都有不同的标题。我需要找出点击图片的标题。但是我在表单提交中的点击功能不起作用。
我的表单是:
  <form action='log.php' id='logForm' method='post' >
  <?
   for($j=1;$j<=5;$j++)
   {
    ?>
   <input type="image" src="<?=$img;?>" title="<?=$url;?> id="<?="image".$j?> class="images" />
    <?
    }
    ?>
   </form>Jquery:
    $("#logForm").submit(function(e)
    {
  $(".advt_image").click(function(event) {
        var href=event.target.title;
    });
           var Form = { };
            Form['inputFree'] = $("#inputFree").val();
         //   if($("#freeTOS").is(":checked"))
                    Form['freeTOS'] = '1';
            $(".active").hide().removeClass('active');
            $("#paneLoading").show().addClass('active');
var url="http://"+href;
      $.post('processFree.php', Form, function(data)
            {
                    if(data == "Success")
                    {
                            $("#FreeErrors").html('').hide();
                            swapToPane('paneSuccess');
                     setTimeout( function() {  location=url }, 2500 );
                    return;
                    }
                    swapToPane('paneFree');
                    $("#FreeErrors").html(data).show();
            });
            return false;
    });如何获取该$("#logForm").submit(function())内点击图片的title值?
我怎么才能使用点击图片的id呢?
发布于 2012-07-03 13:20:31
您可以使用event.target属性
$("#logForm").submit(function(e)
    alert($(e.target).attr('title'));
});http://api.jquery.com/event.target/
更新
我才意识到这行不通。我不认为有一个简单的解决方案。您必须跟踪输入上的单击事件并在以后使用它。
jQuery submit, how can I know what submit button was pressed?
$(document).ready(function() {
    var target = null;
    $('#form :input[type="image"]').click(function() {
        target = this;
        alert(target);
    });
    $('#form').submit(function() {
        alert($(target).attr('title'));
    });
});更新2- .focus不工作,但.click正在使用http://jsfiddle.net/gjSJh/1/
发布于 2012-07-03 13:44:59
在我看来,你有多个提交按钮。不是在提交时调用函数,而是在单击这些按钮时调用它,这样您就可以轻松地访问用户选择的函数:
$('input.images').click(function(e) {
    e.preventDefault(); //stop the default submit from occuring
    alert($(this).attr('title');
   //do your other functions here.
});发布于 2012-07-03 13:56:30
检查下面的代码,你可以得到点击图片的标题。
单击
$(document).ready(function()
{
    $('#logForm').submit(function(e){
         $(".images").click(function(event) {
            alert(event.target.title);
        });
        return false;
    });
});双击
$(document).ready(function()
{
    $('#logForm').submit(function(e){
         $(".images").dblclick(function(event) {
            alert(event.target.title);
        });
        return false;
    });
});https://stackoverflow.com/questions/11304898
复制相似问题