单击具有 UIButton 的 UIWebView 中的锚点
Click an anchor in a UIWebView with a UIButton
我的网页上有一个Javascript函数,我正在UIWebView中显示:
$(document).ready(function() {
// index to reference the next/prev display
var i = 0;
// get the total number of display sections
// where the ID starts with "display_"
var len = $('div[id^="hl"]').length;
// for next, increment the index, or reset to 0, and concatenate
// it to "display_" and set it as the hash
$('#next').click(function() {
++i;
window.location.hash = "hl" + i;
return false;
});
// for prev, if the index is 0, set it to the total length, then decrement
// it, concatenate it to "display_" and set it as the hash
$('#prev').click(function() {
if (i > 1)
--i;
window.location.hash = "hl" + i;
return false;
});
});
所以我需要做的是模拟点击我的 UIButton 时的锚点点击:
- (IBAction)next:(id)sender {
[animalDesciption stringByEvaluatingJavaScriptFromString:@"document.getElementById('"next'").click();"];
}
但这行不通!它在 HTML 页面上效果很好,只需单击标识为"next"的锚点即可。
任何想法为什么在单击按钮时不起作用?
顺便说一句,我可以使用当前的设置调用像myFunc()
这样的标准 JavaScript 函数,但它不会做这样的事情!
任何想法将不胜感激!
你可以为下一个和上一个实现javascript函数,并直接从UIButton调用它。
var i = 0;
function next() {
++i;
window.location.hash = "hl" + i;
return false;
}
function prev() {
if (i > 1)
--i;
window.location.hash = "hl" + i;
return false;
}
$(document).ready(function() {
// get the total number of display sections
// where the ID starts with "display_"
var len = $('div[id^="hl"]').length;
$('#next').click(function() {
next();
});
$('#prev').click(function() {
prev():
});
});
来自您的UIButton的调用将是:
- (IBAction)next:(id)sender {
[animalDesciption stringByEvaluatingJavaScriptFromString:@"next()"];
}
顺便说一句:我想你忘了在next()
函数中使用len
以避免跨过最后一个显示部分。
相关文章:
- 使用clickToggle并在单击另一个元素时关闭元素
- 单击时将焦点更改为元素
- 单击F5时如何停止页面加载
- 通过单击表单中的按钮,在代码生成中使用javascript生成字母数字代码
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 单击jquery清除输入值
- 单击按钮以等待单击按钮
- 在单击href链接的同时下载文件
- 单击顶部导航时如何进行向下滚动效果(向下滑动).
- 使图像在单击时展开到不大于浏览器
- 单击按钮后如何逐个调用分区,上一个分区将隐藏
- 如何在单击复选框后调用控制器方法
- 单击页面上的链接后高度发生变化
- 使用jquery在单击时在单元格中输入值
- 如何区分用户单击链接和在 UIWebView 中执行自动重定向的页面
- 如何在 IOS 上的 UIWebview 中拦截按钮单击
- 以编程方式单击 UIWebView 中的“提交”按钮(无元素 ID、名称、类或标记)
- 单击具有 UIButton 的 UIWebView 中的锚点
- 单击UIWebView中的链接;字符串ByEvaluatingJavaScriptFromString”;
- 如何处理警报单击从UIWebview生成的警报的位置