移动jquery onclick

时间:2011-12-16 17:40:07

标签: jquery mobile jquery-mobile onclick

我正在尝试修复手机版网站。 http://taxilax.com/phone/选择服务类型,然后点击发送信息。 会发生什么是它没有重定向到:

    onclick="form.action='http://taxilax.com/wpcontent/themes/taxi_theme/src/forms/totheairport_process.php';"

它将此添加到网址:http://taxilax.com/phone/#

任何人都知道为什么? 谢谢!

2 个答案:

答案 0 :(得分:1)

更简洁的jQuery方法是修改内联JavaScript并添加这样的事件处理程序:

$('.form-link').bind('click', function (event) {

    //this will prevent the link from doing what it would natively, so it won't append a hash onto the URL
    event.preventDefault();

    //select the form, if there is more than one form then you will need to alter this selctor, and update it's action as well as trigger a submit
    $('form').attr('action', '<URL>').trigger('submit');
});

答案 1 :(得分:0)

您只是更改其操作位置而不是发布表单。您也使用链接发布不是最好的主意的表单。你输入href =“#”就是为什么你的URL上也会出现“#”的原因。我会这样做完全不同,但要快速帮助你:

onclick="form.action='[put your URL here]';form.submit();"

在我看来,这不是一个好习惯,因为你应该为表单提交一个单独的事件处理程序而不是内联,这样可以使代码更易于维护。您还应该使用默认的HTML控件来发布表单。如果你想让它看起来像一个链接,只需设置一个按钮或输入类型提交以取出边框和颜色等。

你也应该把jQuery Mobile视为非常适合移动设备。