Jquery mobile:如何在页面中执行自定义jquery代码 [英] Jquery mobile: how to execute custom jquery code in page

查看:79
本文介绍了Jquery mobile:如何在页面中执行自定义jquery代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用jQuery mobile开发移动网站。

I am currently developing a mobile site using jQuery mobile.

我有一个简单的jQuery,我想按一下按钮执行

I have one simple piece of jQuery that i would like to execute on a button click

例如:点击按钮,显示div。这在第一页或url直接访问的任何页面上都可以正常工作。但是,只要有页面历史记录(即url包含a#),jQuery的自定义片段就不会执行。我假设它与location.hash有关。

eg: Click button, show div. This works fine on the first page, or any page which is directly accessed by url. However, wherever there is page history (ie url contains the a #) the custom snippet of jQuery simply doesn't execute. I'm assuming it's something to do with the location.hash

我通过jQuery移动文档和google进行了很好的拖网,但找不到任何引用这个问题。

I've had a good trawl through the jQuery mobile docs and google but can't find any reference to this issue.

我有什么想法可以让这个jQuery一直执行吗?

Any ideas how i can get this piece of jQuery to execute at all times?

推荐答案

在JS代码中创建一个你想要执行的函数(让我们称之为函数savePerson())。创建按钮:

Create in your JS code a function that you want to execute(let's call it function savePerson()). Create the button with:

<button onclick="savePerson()">Save</button>

这篇关于Jquery mobile:如何在页面中执行自定义jquery代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆