[英]How can I make a iPhone to execute a javascript on a onClick event?
I found this code with a jQuery function to removed the onClick
event ad replace it for an tap
even in iPhone. 我发现此代码带有jQuery函数,可以删除
onClick
事件广告,甚至在iPhone中也可以将其替换为tap
。 I just can't make it work. 我只是无法使其工作。
How can I make and iPhone to execute those JavaScript other than onclick? 除了onclick之外,我该如何让iPhone执行这些JavaScript? I try onChange and no luck neither.
我尝试onChange,也没有运气。
function rebindClicks(){
var userAgent = navigator.userAgent.toLowerCase();
var isIphone = (userAgent.indexOf('iphone') != -1) ? true : false;
if (isIphone) {
// For each event with an inline onclick
$('[onclick]').each(function() {
var onclick = $(this).attr('onclick');
$(this).removeAttr('onclick'); // Remove the onclick attribute
$(this).bind("click", preventClickEvent); // See to it that clicks never happen
$(this).bind('tap', onclick); // Point taps to the onclick
});
}
}
function preventClickEvent(event) {
event.preventDefault();
}
<select name="jumpMenu" class="tableBlackWhite" id="jumpMenu" style="width:275px" onchange="MM_jumpMenu('parent',this,0)" >
<option value="#"><font color="#FF0000" size="3">אנא בחר שיר להשמעה</font></option>
<option onclick="javascript:ajax('/Songs/01.php','SongsContentArea')" value="#"> » נייס באלמו</option>
<option onclick="javascript:ajax('/Songs/02.php','SongsContentArea')" value="#"> » מאתונו</option>
<option onclick="javascript:ajax('/Songs/03.php','SongsContentArea')" value="#"> » פיה אסי</option>
<option onclick="javascript:ajax('/Songs/04.php','SongsContentArea')" value="#"> » טליוסאמה</option>
</select>
It seems like this line: 似乎这行:
$(this).bind('tap', onclick); // Point taps to the onclick
is passing a string instead of a function, since a string is coming from the attr()
. 正在传递字符串而不是函数,因为字符串来自
attr()
。 You can try using an eval
here, but it's really hacky. 您可以在此处尝试使用
eval
,但这确实很麻烦。 Like this: 像这样:
$(this).bind('tap', function() { eval(onclick); }); // Point taps to the onclick
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.