Jquery 将 url 作为变量打开并更改文本
Jquery open url as a variable and change text
>我有这个:
<fieldset id="social_associations" class="">
<a href="/social/login/twitter">Associate your account to twitter</a>
<br>
<a href="/social/login/facebook">Associate your account to facebook</a>
<br>
</fieldset>
我希望一个函数跟踪这些链接中的 URL,但这些 URL 是由脚本生成的,可能会根据用户的个人资料而更改(如果用户已经关联了一个帐户,那么将出现的 URL 将具有"断开连接"而不是"登录"(,因此该函数必须采用链接中显示的任何内容, 它不能硬编码。我不想在单击当前页面时离开它。当单击链接时,我想将文本从关联...以断开连接。一定很容易,但我不知道!
编辑:
我知道这个问题不清楚,所以我在这里改写了一下:JavaScript 单击更改 HRF 并在新窗口中打开
<script>
$(function(){
$('#social_associations').each(function(){
if(/this.href/.test(/login/i)){
this.innerHTML = 'Login';
}
if(/this.href/.test(/disconnect/i)){
this.innerHTML = 'Disconnect';
}
});
});
</script>
<fieldset id="social_associations" class="">
<a href="/social/login/twitter">Associate your account to twitter</a>
<br>
<a href="/social/login/facebook">Associate your account to facebook</a>
<br>
</fieldset>
我不确定这是否是你想要的,所以告诉我它是否不是:)
要更改链接文本,我会这样做。至于问题的其余部分,我不确定我是否理解。
$( '#social_associations' )
.on( 'click', 'a[href*="/login/"]', function(){
// not sure what 'follow the URLs within these links' means, but do it here
//then change the link text
$( this ).text( $( this ).text().replace( /Associate/i, "disconnect" ) );
})
.on( 'click', 'a[href*="/disconnect/"]', function(){
// not sure what 'follow the URLs within these links' means, but do it here
//then change the link text
$( this ).text( $( this ).text().replace( /disconnect/i, "Associate" ) );
})
相关文章:
- 来自文本输入null的html javascript变量
- 将文本框中的值用于按钮窗体操作上的变量
- 操作javascript变量[HTML]以只显示文本
- 使用JSON文件中的变量(字符串)填充文本区域
- 仅当变量有值时才显示D3文本标签
- 如何在外部文档中使用javascript将文本区域的内容保存为变量
- 如何在Jquery函数中为自动完成文本区域指定一个变量作为Id
- 如何获取Session变量中的锚文本
- PHP/Ajax/jquery/JON-在Ajax Post之后将echo文本中的一部分作为变量返回
- 文本输入值中的JavaScript变量
- 键/值对的JavaScript数组使用文本变量名作为键
- 需要将长文本变量从JavaScript传递到PHP
- 如何使函数中的tkinter画布文本变量
- getXMLHTTP statusObject中的文本变量未找到状态=200
- 如何替换实时预览上的文本变量
- 文本变量为html,来自另一个站点的文件
- 如何将json文件转换为javascript中的文本变量
- 如何更改包含文本化值的文本变量的字体族
- 减去两个文本变量
- 使用jQuery从文本变量中给组合框赋值