简体   繁体   English

如何制作iPhone以在onClick事件上执行JavaScript?

[英]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.

相关问题 如何使OnClick事件仅执行一次? - How can I get a OnClick Event to execute only once? 如何使onclick事件选择使用Javascript单击的元素的ID? - How can I make my onclick event select the id of the element that was clicked using Javascript? 如何为动态添加的复选框创建 onclick 事件? (JavaScript) - How do I make an onclick event for a dynamically added checkbox? (JavaScript) 如何使我的Javascript事件处理程序仅执行一次? - How can I make my Javascript event handler execute just once? 如何从JavaScript调用LinkBut​​ton OnClick事件? - How can I call LinkButton OnClick Event from JavaScript? 如何在JavaScript中以#开头的ID上进行onclick事件 - how to make onclick event on an id beginning by a # in javascript 无法使用“ onclick”按钮执行JavaScript事件 - Can't execute a JavaScript event using 'onclick' button 如何使用 Javascript 使 div 出现 onclick? - How can I make a div appear onclick using Javascript? Javascript的object.onClick运行函数而不是设置onClick,如何防止这种情况发生,仅执行onClick函数? - Javascript's object.onClick runs the function instead of setting onClick, how can I prevent that from happening and only execute the function onClick? 如何在 NextJs 中使用 onclick 执行 function? - How can I execute a function with onclick in NextJs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM