douchuang1861 2017-06-23 13:52
浏览 42
已采纳

如何在选择除一个链接之外的所有链接时运行脚本

I'm trying to make a script run when you select a link. I have that part working, however I want it to not run when you select the main one (English). I'm sure I'm missing something basic but I have no idea what it could be. Here is what I have so far:

Script:

function disclaimer() {
  if ($( "a[title!='English']")) {
     alert('Disclaimer here');
  }
}

PHP:

$block_content .= '<a href="#top" 
onclick="doGTranslate(\''.$gtranslate_main_lang.'|'.$lang.'\'); 
disclaimer();jQuery(this).parent().parent().find(\'div.selected 
a\').html(jQuery(this).html());" title="'.$lang_name.'" class="nturl '.
($current_language == $lang ? ' selected' : '').'"><span class="gflag" 
style="background-position:-'.$flag_x.'px -'.$flag_y.'px;"><img 
src="'.base_path().drupal_get_path('module', 'gtranslate').'/gtranslate-
files/blank.png" height="16" width="16" alt="'.$lang_name.'" />
</span>'.$lang_name.'</a>';

Produced HTML:

<a href="#top" onclick="doGTranslate('en|en'); 
disclaimer();jQuery(this).parent().parent().find('div.selected 
a').html(jQuery(this).html());" title="English" class="nturl  selected">
<span class="gflag" style="background-position:-0px -0px;"><img 
src="/sites/all/modules/contrib/gtranslate/gtranslate-files/blank.png" 
height="16" width="16" alt="English"></span>English</a>

<a href="#top" onclick="doGTranslate('en|fr'); 
disclaimer();jQuery(this).parent().parent().find('div.selected 
a').html(jQuery(this).html());" title="French" class="nturl "><span 
class="gflag" style="background-position:-200px -100px;"><img 
src="/sites/all/modules/contrib/gtranslate/gtranslate-files/blank.png" 
height="16" width="16" alt="French"></span>French</a>

<a href="#top" onclick="doGTranslate('en|de'); 
disclaimer();jQuery(this).parent().parent().find('div.selected 
a').html(jQuery(this).html());" title="German" class="nturl "><span 
class="gflag" style="background-position:-300px -100px;"><img 
src="/sites/all/modules/contrib/gtranslate/gtranslate-files/blank.png" 
height="16" width="16" alt="German"></span>German</a>

As I said, I want the script to run when French or German are selected, but not English. I've tried several things but nothing seems to work. Any help or point in the right direction is greatly appreciated. If I need to post anything else that might help you, please let me know!

  • 写回答

1条回答 默认 最新

  • dongzheng8463 2017-06-23 14:06
    关注

    Example links - modifed to use this object identifier Not tested but looks like it should work ~ no doubt jQuery has a far more refined way of doing it though.

    <a href='#' onclick='disclaimer(this)' title='English'>English</a>
    <a href='#' onclick='disclaimer(this)' title='French'>French</a>
    <a href='#' onclick='disclaimer(this)' title='German'>German</a>
    
    
    function disclaimer(n) {
        if( n.hasAttribute('title') && n.getAttribute('title')!='English' )alert('Disclaimer here');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应