javascript - rel 中存在多个值并使用 javascript 或 jquery 进行访问

标签 javascript jquery html

我想要进行如下所示的检查,为此我想要 2 个值。是否可以在 rel 中传递多个值?任何帮助都会很好。

<a href="#" rel='.$row['Table_ID']. 's''></a>

js:

// Get current row id.
   var Row_id = $(this).attr('rel');

else if(SelectedTab == 'Drug Seizure')
{
    if(Row_id == 's')
    {

    }

    else
    {
        Table_name = "SOME";
        Column_name = "Some_ID";
    }
}

最佳答案

不要使用 rel 来表示,rel if 表示与文档的关系。如果您使用 html5,只需使用数据(您可以将其用于任何元素):

<div id="example" data-numbers="123" data-othervalue="abc"/>

alert( $('#example').attr('data-numbers') );
alert( $('#example').attr('data-othervalue') );
// Or
alert( $('#example').data('numbers') );
alert( $('#example').data('othervalue') );

向您展示另一种方法:

<div id="example" data-mixed="123,abc"/>
var info = $('#example').attr('data-mixed').split(","); // split on comma
alert( info[0] ); // 123
alert( info[1] ); // abc

如果您不能使用 html5,您可以使用其他属性,如标题、类或 ID,并使用相同的策略。但这些应该被视为异常(exception)。还必须注意的是,这是客户端。因此你不能相信这个值(value)。始终检查服务器端。

关于javascript - rel 中存在多个值并使用 javascript 或 jquery 进行访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22593044/

相关文章:

javascript - 在 jQuery 中发送给 .always 的参数是什么?

javascript - 检索当前行的表行索引

jquery - CSS 3 透视图和 z-index 不兼容

css - 无法在 HTML/CSS 中将文本居中

javascript - Jssor Slider 如何将箭头添加到缩略图图库

html - 修复了菜单问题,修复后菜单垂直堆叠

javascript - 如何更正 NodeJS 找不到已安装的包?

javascript - 使用 ADFS 和 nginx 实现 SSO

javascript - 如何在 div 最终淡入(JS、jQuery)后更改文本?

javascript - 更改滚动事件的 Logo 大小